1.JavaScript Creating nodes
CreateElement (); Note: Create an element node.
For example:
var v = document.createelement ("P");
createTextNode (); Note: Create a text node.
For example:
var v = document.createtextnode ("Everyone good");
2.js node operation
AppendChild (); Note: Add a child node to the current node
var p = document.createelement ("P");
var text = document.createTextNode ("Everyone good");
P.apendchild (text); Note: add
RemoveChild (); Delete child nodes
var div = document.createelement ("div");
var p = document.createelement ("P");
Div.removechild (P);
ReplaceChild (); Note: Replace child nodes
var p = document.createelement ("P");
var text = document.createTextNode ("Everyone good");
P.apendchild (text); Note: Add text to P
var Text1 = document.createTextNode ("Good for You");
P.apendchild (Text1,text); Note: This will change the text to Text1.
InsertBefore (); Before inserting one node into another node.
var div = document.createelement ("div");
var p = document.createelement ("P");
Div.apendchild (P); Note: Add P to Div, this time p position in Div is the first
var P1 = document.createelement ("H1");
Div.insertbefore (P,P1); Note: This puts H1 in front of P, where p is the second position in the Div.
2.JavaScript element content and properties operations
InnerHTML; Gets the HTML for the specified element. ClassName; Gets the class attribute of the specified element. style; Gets the style style of the specified element. GetAttribute (); Gets the property value of the specified element. SetAttribute (); Sets a property for the new element. RemoveAttribute (); Deletes the properties of the specified element.
For example
<div id = "DIV1" >abc<div/>
document.getElementById ("Div1"). innerhtml= "CBA";
document.getElementById ("Div1"). SetAttribute ("style", "Color: #000;");
JavaScript creation Node