This rule raises an issue when parentNode.removeChild(childNode) is used instead of the more direct childNode.remove()
method.
The traditional way to remove a DOM element in JavaScript was to call parentNode.removeChild(childNode). This approach requires you to
first access the parent node, then call removeChild with the child node as an argument.
Modern browsers support the remove() method directly on DOM nodes, which provides a cleaner and more intuitive API. Using
childNode.remove() is simpler because:
The remove() method has been widely supported across browsers for many years and is the recommended approach for removing DOM
elements.
Using the older removeChild pattern makes code more verbose and harder to read. While functionally equivalent, the modern
remove() method improves code maintainability and follows current best practices for DOM manipulation.
Replace parentNode.removeChild(childNode) with childNode.remove(). This directly removes the element without needing to
access its parent.
parentNode.removeChild(foo); // Noncompliant parentNode.removeChild(this); // Noncompliant
foo.remove(); this.remove();