Skip to content

Prefer Node#append() over Node#appendChild() ​

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

Enforces the use of, for example, document.body.append(div); over document.body.appendChild(div); for DOM nodes. There are some advantages of using Node#append(), like the ability to append multiple nodes and to append both DOMString and DOM node objects.

Fail ​

js
foo.appendChild(bar);

Pass ​

js
foo.append(bar);
foo.append('bar');
foo.append(bar, 'baz');

Released under the Apache License 2.0.