javascriptrecoveryremovechildparent-node

Recover item deleted with parentNode.removeChild


Do you know how I could recover an item deleted with JavaScript in the following way:

elem1.parentNode.removeChild(elem1);

Solution

  • As written in the MDN documentation removeChild will return a reference to the removed child node. Usage like this:

    var oldChild = element.removeChild(child);
    element.removeChild(child);
    

    Further:

    The removed child node still exists in memory, but is no longer part of the DOM. You may reuse the removed node later in your code, via the oldChild object reference.