Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 855 Bytes

prefer-node-remove.md

File metadata and controls

26 lines (19 loc) · 855 Bytes

Prefer remove over parentNode.removeChild and parentElement.removeChild

Enforces the use of, for example, child.remove(); over child.parentNode.removeChild(child); and child.parentElement.removeChild(child); for DOM nodes. The DOM function .remove() is preferred over the indirect removal of an object with .removeChild().

This rule is fixable.

Fail

foo.parentNode.removeChild(foo);
foo.parentElement.removeChild(foo);
this.parentNode.removeChild(this);
this.parentElement.removeChild(this);
foo.parentNode.removeChild(bar);
foo.parentElement.removeChild(bar);
this.parentNode.removeChild(foo);
this.parentElement.removeChild(foo);

Pass

foo.remove();
this.remove();