Related methods of JavaScript elements

Source: Internet
Author: User

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

Related Article

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.