Home >Web Front-end >Front-end Q&A >How to delete nodes in html

How to delete nodes in html

青灯夜游
青灯夜游Original
2021-05-17 13:52:154328browse

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.

How to delete nodes in html

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn