js removeChild() Usage<body> <p id="p1">welcome to <b>javascript</b> world !</p> <script language="javascript" type="text/javascript"> <!-- function nodestatus(node) { var temp=""; if(node.nodeName!=null) { temp+="nodeName="+node.nodeName+"/n"; } else temp+="nodeName=null /n"; if(node.nodeType!=null) { temp+="nodeType="+node.nodeType+"/n"; } else temp+="nodeType=null /n"; if(node.nodeValue!=null) { temp+="nodeValue="+node.nodeValue+"/n"; } else temp+="nodeValue=null /n"; return temp; } var parent=document.getElementById("p1"); var msg="parent node/n"+nodestatus(parent)+"/n"; //Return the last child of element node p last=parent.lastChild; msg+="Before deletion: lastChild--"+nodestatus(last)+"/n"; //Delete the last child of node p and becomes b parent.removeChild(last); last=parent.lastChild; msg+="After deletion: lastChild--"+nodestatus(last)+"/n"; alert(msg); --> </script> </body> <html><head><title>js controls adding and deleting nodes</title></head><script type="text/javascript"> var all; function addParagraph() { all = document.getElementById("paragraphs").childNodes; var newElement = document.createElement("p"); var seq = all.length + 1; //Create a new attribute var newAttr = document.createAttribute("id"); newAttr.nodeValue = "p" + seq; newElement.setAttribute(newAttr); //Create text content var txtNode = document.createTextNode("paragraphs" + seq); //Add node newElement.appendChild(txtNode); document.getElementById("paragraphs").appendChild(newElement); } function delParagraph() { all = document.getElementById("paragraphs").childNodes; document.getElementById("paragraphs").removeChild(all[all.length -1]); }</script><style> p{ background-color: #e6e6e6 ; }</style><body><center> <input type="button" value="Add node" onclick="addParagraph();"/> <input type="button" value="Delete node" onclick="delParagraph();"/> <div id="paragraphs"> <p id="p1">Paragraph1</p> <p id="p2">Paragraph2</p> </div></center></body></html>The above article "JS operation DOM" - a simple example of adding and deleting nodes is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.