This article describes the usage of the DOM node removal function removeChild(). Share it for your reference. The specific analysis is as follows:
To delete a node in DOM, you must stand at the height of the parent node to delete it. The code is as follows:
Copy the code as follows: <html>
<head>
<script type="text/javascript">
function t(){
//Thoughts: 1. First find the node to be deleted; 2. Find its parent node and delete the child node from the perspective of the parent node.
var nodeul = document.getElementsByTagName('ul')[0];//Find the parent node
var li_lan = nodeul.children[2];//Find the child node to be deleted
nodeul.removeChild(li_lan);//Use removeChild() function to delete
}
</script>
</head>
<body>
<div id="container">
<ul>
<li>Spring</li>
<li>Summer</li>
<li>Blue Sky</li>
<li>Autumn</li>
<li>Winter</li>
</ul>
</div>
<div id="copyul">
</div>
<hr />
<button onclick="t()" value="">Delete a child node</button>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.