<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Untitled Document</title><Script>window.onload= function() { varOtext=document.getElementById ('Text1'); varobtn=document.getElementById ('btn'); varOul=document.getElementById ('UL1'); Obtn.onclick= function() { //Creating an LI element varOLi=Document.createelement ('Li');//document.createelement (tag name); Create elementoli.innerhtml=Otext.value; //Create a DELETE element varOA=Document.createelement ('a'); Oa.innerhtml= 'Delete'; Oa.href= 'javascript:;'; //Delete EventOa.onclick= function() {Oul.removechild ( This. parentnode);//parent. RemoveChild (the element to be removed); the parent of the element to be deleted is the current} oli.appendchild (OA); /*parent. InsertBefore (new element, inserted element) method inserts a new element in front of the specified element under IE if the node of the second parameter does not exist, the error will be in the other standard browser if the second argument Number of nodes does not exist, it will be added in the form of AppendChild Oul.insertbefore (OLi, oul.children[0]); */ if(oul.children[0]) {Oul.insertbefore (oLi, oul.children[0] ); } Else{oul.appendchild (oLi);//the parent. AppendChild (the element to be added) method appends the child element Oul.appendchild (oLi); } } }</Script></Head><Body> <inputtype= "text"ID= "Text1" /><inputtype= "button"value= "message"ID= "BTN" /> <ulID= "UL1"></ul></Body></HTML>
Create a DELETE element Appendchild,removechild,createelement,insertbefore