Element nodes in the DOM tree:
Node attributes:
Value of X. nodevalue Node object X (read-only)
The nodename of the element node is the same as the label name.
The nodename of the attribute node is the name of the attribute.
The nodename of the text node is always # text
The nodename of the document node is always # documentX. Name of the nodename Node object x
The nodevalue of an element node is undefined.
The nodevalue of a text node is the text itself.
The nodevalue of the attribute node is the attribute value.
X. nodetype Node object X type (read-only)
Element type |
Node Type |
Element |
1 |
Attribute |
2 |
Text |
3 |
Note |
8 |
Document |
9 |
Node positioning:
X. parentnode Node object x parent node
X. child node of childnodes Node object x
X. firstchild
X. lastchild
X. nextsibling
X. previussibling
Nodea. firstchild = nodea1
Nodea. lastchild = nodea3
Nodea. childnodes. Length = 3
Nodea. childnodes [0] = nodea1
Nodea. childnodes [1] = nodea2
Nodea. childnodes [2] = nodea3
Nodea1.parentnode = nodea
Nodea1.nextsibling = nodea2
Nodea3.prevsibling = nodea2
Nodea3.nextsibling = NULL
Nodea. lastchild. firstchild = nodea3a
Nodea3b. parentnode. parentnode = nodea
How to search and operate nodes in DOM:
Insertbefore () inserts a new subnode before referring to the subnode. If the subnode referenced is null, the new subnode is inserted as the last subnode of the call node.
ReplaceChild () replaces oldchild with the specified newchild in the childnodes set. If the replacement is successful, oldchild is returned. If newchild is null, you only need to delete oldchild.
Removechild () deletes the node specified by removechild from the node's childnodes set. If the node is deleted successfully, the deleted child node is returned.
Appendchild () adds a new node to the end of the childnodes set. If yes, the new node is returned.
Clonenode () creates a new and replicated node. If the input parameter is true, it also copies the child node. If the node is an element, it also copies the corresponding attribute, return the new node.
Getelementbyid () searches for element nodes by ID
Getelementsbytagname () searches for element nodes by tagname
Createelement () create a new element node
Createtextnode () create a new text node
Getattribute () gets the attribute value
Setattribute () sets the attribute value
Node list:
Returned by the getelementsbytagname () method and childnodes attribute.
X. Length node list x length (number of nodes)
Attribute node list:
The attributes attribute of the element node returns the list of attribute nodes.
X. length the length of the list of attribute nodes (number of attribute nodes)
X. getnameditem () returns the attribute node
Note:
<Year> 2005 </year>, Element node <year>, has a text node with a value of "2005.
"2005"No<Year> value of the element! Text is always stored in text nodes.