Posted By: Josh
var element = document.getElementById("element-id"); element.parentNode.removeChild(element);
The DOM is organized in a tree of nodes, where each node has a value, along with a list of references to its child nodes. So
element.parentNode.removeChild(element) mimics exactly what is happening internally: First you go the parent node, then remove the reference to the child node.
- Remove elements via the parent node, as in the question,
- modify the native DOM functions, as in Johan Dettmar’s answer, or
- use a DOM4 polyfill.