First of all, there are three major nodes in the DOM, namely, element node, text node, attribute node
ELEMENT node: Forms the basis of the DOM. ,
Text node: contained in the element node.
Attribute nodes: Elements can contain attributes that are used to make more specific descriptions of elements, such as Id,name.
Take the following demo as an example:
<script>function() { var element = document.getElementById ("span" ); var text = element.firstchild; var property = document.getElementById ("span"). GetAttributeNode ("id"); }</script><body> <div> <span id= "span" > Text node </span> </div>< /body>
( a) The NodeName property contains the name of a node.
The nodeName of the element node is the label name (the returned name is uppercase)
The nodeName of the attribute node is the property name (the returned name is uppercase)
The nodeName of a text node is always #text
The nodeName of the document node is always #document
Note: The label name of the XML element contained in NodeName is always capitalized
Alert ("This is the return value of the element node:" + Element.nodename); // return the label name span, note that it is uppercase alert ("This is the return value of the text node:" + Text.nodename); // The returned #textalert ("This is the return value of the attribute node:" + Property.nodename); // returned is the property name, here is the ID
( II) nodevalue
For text nodes, the NodeValue property contains text.
For attribute nodes, the NodeValue property contains the property value.
The NodeValue property is not available for document nodes and ELEMENT nodes.
Alert ("This is the return value of the element node:" + Element.nodevalue); // itself is meaningless, here is the experiment, and the return is nullalert ("This is the return value of the text node:" + Text.nodevalue); // returns the text value of the text node alert ("This is the return value of the attribute node:" + Property.nodevalue); // returns the property value, which is the property value of the ID myspan
( c) NodeType
The NodeType property returns the type of the node.
3 of the types we use:
NodeType = = 1: element node
NodeType = = 2: Attribute node
NodeType = = 3: Text node
Note Comments 8
Document 9
Alert ("This is the return value of the element node:" + Element.nodetype); // element Node returns 1 Alert ("This is the return value of the text node:" + Text.nodetype); // text node returns 3 Alert ("This is the return value of the attribute node:" + Property.nodetype); // Property node returns 2
___________________________
Original: Http://www.tuicool.com/articles/zANnye
NodeType, NodeName and NodeValue