JS DOM Programming Art--dynamically creating tags--JS learning notes 2015-7-13 (83rd Day)

Source: Internet
Author: User

Dom Method:

1, createelement

Syntax: document.createelement (nodeName)

For example: Document.createelement ("P"); A P element is created;

2, AppendChild

Syntax: Parent.appendchild (Child)

3, Creattextnode

Syntax: document.createTextNode (text)

Example.js

/*window.onload = function () {var para = document.createelement ("P");    var testdiv = document.getElementById ("Testdiv");    Testdiv.appendchild (para);    var txt = document.createtextnode ("Hello World"); Para.appendchild (TXT); Note that there is no need to enclose the parentheses in the brackets for example: Para.appendchild ("TXT") is wrong to write;}*///method Two (because the AppendChild method can also be used to connect those nodes that have not yet become part of the document tree)://window.onload = function () {//var para = document.createelement ("P");//var txt = document.createtextnode ("Hello World");//para.appendchild (TXT);//var testdiv = document.getElementById ("Testdiv");//Testdiv.appendchild (para);    // }window.onload=function(){    varPara = document.createelement ("P"); varTXT1 = document.createTextNode ("This is"); varemphasis = document.createelement ("em"); varTXT2 = document.createTextNode ("My"); varTXT3 = document.createTextNode ("content.");    Para.appendchild (TXT1);    Emphasis.appendchild (TXT2);    Para.appendchild (emphasis);    Para.appendchild (TXT3); varTestdiv = document.getElementById ("Testdiv"); Testdiv.appendchild (para);}

JS DOM Programming Art--dynamically creating tags--JS learning notes 2015-7-13 (83rd Day)

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.