Append node
<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >Li{border:1px solid Red;} Div{border:5px solid Green;}</style>varI=0;d ocument. getElementsByTagName (' input ') [0].onclick=function() {i++; OB=document.createelement ("Li"); OB. innerhtml= "li-" +i; Document. getElementById ("Ul1").appendchild (OB);} Document. getElementsByTagName (' input ') [1].onclick=function() {Divob=document.getelementbyid ("Div1"); Ob1=document.createelement ("div"); Ob1. innerhtml= "Div-n"; Document. Body.insertbefore (Ob1,divob);} Document. getElementsByTagName (' input ') [2].onclick=function(){ varFob=document.getelementbyid (' Ul1 '); varCob=document.getelementbyid (' Ul1 ').ChildNodes; Alert (COb.length); for(vari=cob.length-1;i>=0;i--) {fOb.removechild (Cob[i]); }}</script>
JavaScript Append node