<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Title</title> <style>Div{width:200px;Height:200px;Border:1px solid Red; } </style></Head><Body><inputtype= "button"value= "Show effect"ID= "BTN"/><inputtype= "button"value= "Kill first child element"ID= "BTN2"/><inputtype= "button"value= "Kill all child elements"ID= "Btn3"/><DivID= "DV"></Div><Scriptsrc= "Common.js"></Script><Script> varI=0; my$ ("btn"). onclick=function() {i++; varobj=Document.createelement ("input"); Obj.type="Button"; Obj.value="Button"+i; //my$ ("DV"). appendchild (obj);//Append child elements //inserts a new child element in front of the first child elementmy$ ("DV"). InsertBefore (obj,my$ ("DV"). Firstelementchild); //my$ ("DV"). ReplaceChild ();---play by yourself }; my$ ("btn2"). onclick=function () { //remove the first child element in a parent elementmy$ ("DV"). RemoveChild (my$ ("DV"). Firstelementchild); }; my$ ("Btn3"). onclick=function () { //Click the button to delete all the child elements in the Div //determines if there is no first child element in a parent element while(my$ ("DV"). Firstelementchild) {my$ ("DV"). RemoveChild (my$ ("DV"). Firstelementchild); } };</Script></Body></HTML>
Related methods of JavaScript elements