1. html Dom is a tree object
2. Each node contains some information about the node, which is:
1. nodename
The nodename attribute contains the name of a node.
* The nodename of an element node is the label name.
* The nodename of the attribute node is the attribute name.
* The nodename of the text node is always # text
* The nodename of the document node is always # document
Note: The Tag Name of the XML element contained by nodename is always capitalized.
2. nodevalue
For text nodes, the nodevalue attribute contains text.
For an attribute node, the nodevalue attribute contains the attribute value.
The nodevalue attribute is unavailable for document nodes and element nodes.
3. nodetype
The nodetype attribute returns the node type.
The most important node types are:
Element type |
Node Type |
Element |
1 |
Attribute |
2 |
Text |
3 |
Note |
8 |
Document |
9
|
3. Modify nodes
1. [newfathernode]. appendchild ([childnode])
This operation changes the relationship between newfathernode and childnode to a parent-child node, and automatically causes the oldfathernode of childnode to not own this childnode node.
2. [newfathernode]. removechild ([childnode])
IV,ProgramExampleCopyCodeThe Code is as follows: <HTML>
<Body>
<Div id = "div1">
<Div id = "div3">
</Div>
</Div>
<Div id = "div2">
</Div>
<SCRIPT>
Function $ ID (ID ){
Return document. getelementbyid (ID );
}
Function countnodes (ARR ){
VaR Len = arr. length;
VaR I = 0;
While (Len --){
(ARR [Len]. nodetype = 1) & I ++;
}
Return I;
}
Window. onload = function (){
Alert (countnodes ($ ID ("div2"). childnodes ));
$ ID ("div2"). appendchild ($ ID ("div3 "));
Alert (countnodes ($ ID ("div1"). childnodes ));
Alert (countnodes ($ ID ("div2"). childnodes ));
}
</SCRIPT>
</Body>
</Html>