Javascript removeChild(): remove node

In Javascript, there is only one method for removing nodes: removeChild().

The removeChild()  method is used to remove a child node of the parent node.

Syntax: parent.removeChild(thisNode) parameter description:
    

Parameter Description
thisNode The current node, the node to be deleted
parent The parent node of the current node, i.e. thisNode.parentNode


For example, the statement to delete the node with id="demo" is:

  1. var thisNode=document.getElementById("demo");
  2. thisNode.parentNode.removeNode(thisNode);


For example, to delete a node:

  1. <div id="demo">
  2. < div id = "thisNode" > click to delete me </ div >
  3. </div>
  4. <script type="text/javascript">
  5. document.getElementById("thisNode").onclick=function(){
  6. this.parentNode.removeChild(this);
  7. }
  8. </script>


Example demonstration:

click delete me


It can be seen that although Javascript only provides a method to delete nodes, it is enough.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326924921&siteId=291194637