JavaScript creates only one element, multiple clicks do not create

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title></title>    <style>Div{width:300px;Height:300px;Border:1px solid Pink;        }    </style></Head><Body><inputtype= "button"value= "Create button"ID= "BT"/><DivID= "DV"></Div><Scriptsrc= "Common.js"></Script><Script>    //There is delete, none is created    //be responsible for deleting//my$ ("BT"). onclick = function () {////Determine if there is no such element in the DIV is deleted////Determine if the child element of this button exists//if (my$ ("BT2")) {//Is true there is//my$ ("DV"). RemoveChild (my$ ("BT2"));//        }//var btobj = document.createelement ("input");//btobj.type = "button";//btobj.value = "button";//btobj.id = "BT2";//my$ ("DV"). AppendChild (btobj);//    };    //None created    //determine if there is no such element in the Div, none created    //determine if the child element of this button existsmy$ ("BT"). onclick= function () {      if(!my$ ("BT2")) {          varBtobj=Document.createelement ("input"); Btobj.type= "Button"; Btobj.value= "Button"; Btobj.id= "BT2"; my$ ("DV"). appendchild (Btobj); }    };</Script></Body></HTML>

JavaScript creates only one element, multiple clicks do not create

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.