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)