Start with the method:
1. delete a node. Removechild ():
<Body>
<Div id = "cssrain">
<Div id = "A"> A </div>
<Div id = "B"> B </div>
<Div id = "C"> C </div>
</Div>
</Body>
<SCRIPT>
VaR MSG = Document. getelementbyid ("cssrain ");
VaR B = Document. getelementbyid ("B ");
MSG. removechild (B );
</SCRIPT>
If you do not know the parent node of the node to be deleted? You can use the parentnode attribute.
For example:
<Body>
<Div id = "cssrain">
<Div id = "A"> A </div>
<Div id = "B"> B </div>
<Div id = "C"> C </div>
</Div>
</Body>
<SCRIPT>
VaR B = Document. getelementbyid ("B ");
VaR c = B. parentnode;
C. removechild (B );
</SCRIPT>
2. Replace the node. Repalcechild ()
Element. repalcechild (newnode, oldnode); // The new node is a guest and must be served first .. The oldnode must be a subnode of the element.
Example:
<Body>
<Div id = "cssrain">
<Div id = "A"> A </div>
<Div id = "B"> B </div>
<Div id = "C"> C </div>
</Div>
</Body>
<SCRIPT>
VaR cssrain = Document. getelementbyid ("cssrain ");
VaR MSG = Document. getelementbyid ("B ");
VaR para = Document. createelement ("p ");
Cssrain. replaceChild (para, MSG );
</SCRIPT>
3. Search for nodes
Compared with the above method, it is relatively simple to search for nodes.
Because many people have used it. (Remember that the first sentence I know about JS is getelementbyid ();)
Getelementbyid ();
Returns an object with attributes such as nodename, nodetype, parentnode, and childnodes.
getelementsbytagname () searches for all elements of the tag name.
A collection is returned. Each object can be retrieved cyclically. The object has attributes such as nodename, nodetype, parentnode, and childnodes.
example:
var PS = document. getelementsbytagname ("P");
for (VAR I = 0; I PS [I]. setattribute ("title", "hello");
// you can also use: PS. item (I ). setattribute ("title", "hello");
}