DOM Removing an element


Example

An element can be removed by calling remove() on it. Alternatively, one can call removeChild() on its parent. removeChild() has better browser support than remove().

element.remove();

element, and all its childnodes, are removed from the DOM.

parentElement.removeChild(element);

element, and all its childnodes, are removed from the DOM.

In any case, one can insert this node in the DOM at a later point in time as long as there are still references to this node.