Home >Web Front-end >Front-end Q&A >How to delete nodes in html
In html, you can use the removeChild() method of the DOM Element object to delete nodes; you need to first obtain the specified html node and its parent node, and then use the "parent node.removeChild (specified html node)" statement Just delete it.
The operating environment of this tutorial: windows7 system, HTML5&&javascript version 1.8.5, Dell G3 computer.
Delete existing HTML elements
<div id="div1"> <p id="p1">这是一个段落。</p> <p id="p2">这是另一个段落。</p> </div> <script> var parent=document.getElementById("div1"); var child=document.getElementById("p1"); parent.removeChild(child); </script>
Instructions:
Find the location of the element to be deleted first, and then
The element to be deleted
deletes the element from that location.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of How to delete nodes in html. For more information, please follow other related articles on the PHP Chinese website!