Deleting a DOM node is much easier than inserting it.
To delete a node, first obtain the node itself and its parent node, and then call the parent node's removechild to erase itself:
<! Doctype Html>"Utf-8"><title>javascript</title>"List"> <p id="Java">Java</p> <p id="python">Python</p> <p id="Scheme">Scheme</p></div><script>'Use Strict';//get the node that needs to be deletedvarSelf = document.getElementById ('Java');//Gets the parent node that needs to delete the nodevarParent =self.parentelement;//to delete an operation//var removed = Parent.removechild (self);parent.removechild (self);</script></body>Results:
The deleted node is not in the document tree, but it remains in memory and can be added to another location at any time.
! Doctype Html>"Utf-8"><title>javascript</title>"List"> <p id="Java">Java</p> <p id="python">Python</p> <p id="Scheme">Scheme</p></div><script>'Use Strict';//get the node that needs to be deletedvarSelf = document.getElementById ('Java');//Gets the parent node that needs to delete the nodevarParent =self.parentelement;//to delete an operation//var removed = Parent.removechild (self);varremoved =parent.removechild (self); Console.log (removed===Self );</script></body>Results:
JS Browser Operation DOM Delete Dom