Create a DELETE element Appendchild,removechild,createelement,insertbefore

Source: Internet
Author: User

<!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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.