Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 1.79 KB

prefer-modern-dom-apis.md

File metadata and controls

52 lines (36 loc) · 1.79 KB

Prefer modern DOM APIs

Enforces the use of:

There are some advantages of using the newer DOM APIs, like:

  • Traversing to the parent node is not necessary.
  • Appending multiple nodes at once.
  • Both DOMString and DOM node objects can be manipulated.

This rule is fixable.

Fail

foo.replaceChild(baz, bar);

foo.insertBefore(baz, bar);

foo.insertAdjacentText('position', bar);

foo.insertAdjacentElement('position', bar);

Pass

foo.replaceWith(bar);
foo.replaceWith('bar');
foo.replaceWith(bar, 'baz'));

foo.before(bar)
foo.before('bar')
foo.before(bar, 'baz')

foo.prepend(bar)
foo.prepend('bar')
foo.prepend(bar, 'baz')

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

foo.after(bar)
foo.after('bar')
foo.after(bar, 'baz')