Node information
Each node has properties that contain some information about the node. These properties are:
NodeName (node name)
NodeValue (node value)
NodeType (node type)
NodeType
The NodeType property returns the type of the node.
The most important node types are:
Element type |
Node type |
Element (Element_node) |
1 |
Properties (Attribute_node) |
2 |
Text (Text_node) |
3 |
Note (comment_node) |
8 |
Document (Document_node) |
9 |
In the actual application, is often used is the element node, attribute node and text node, below we through the small section code to explain
1: Element node
ELEMENT Node code
- <HTML>
- <HEAD>
- <title> Empty Valley leisurely </title>
- </HEAD>
- <BODY>
- <table>
- <tr>
- <TD Id="John" name="myname">john</td>
- <TD>doe</td>
- <TD Id="Jack">jack</td>
- </tr>
- </Table>
- <script>
- var d = document.getElementById ("John");
- Alert (D.nodetype)
- Alert (D.nodename)
- Alert (D.nodevalue)
- </Script>
- </BODY>
- </HTML>
Analyze the result of the run with the values of the three properties:
Nodetype:element_node
NodeType Value: 1
NodeName: Element tag name//here is TD
Nodevalue:null
2: Attribute node
Attribute Node code
- <HTML>
- <HEAD>
- <title> Empty Valley leisurely </title>
- </HEAD>
- <BODY>
- <table>
- <tr>
- <TD Id="John" name="myname">john</td>
- <TD>doe</td>
- <TD Id="Jack">jack</td>
- </tr>
- </Table>
- <script>
- var d = document.getElementById ("John"). GetAttributeNode ("name");
- Alert (D.nodetype)
- Alert (D.nodename)
- Alert (D.nodevalue)
- </Script>
- </BODY>
- </HTML>
Analyze the result of the run with the values of the three properties:
Nodetype:attribute_node
NodeType Value: 2
NodeName: Attribute name//name
NodeValue: Attribute value//myname
3: Text node
Text Node code
- <HTML>
- <HEAD>
- <title>new Document</title>
- </HEAD>
- <BODY>
- <table>
- <tr>
- <TD Id="John" name="myname">john</td>
- <TD>doe</td>
- <TD Id="Jack">jack</td>
- </tr>
- </Table>
- <script>
- var d = document.getelementsbytagname ("TD") [0].firstchild
- Alert (D.nodetype)
- Alert (D.nodename)
- Alert (D.nodevalue)
- </Script>
- </BODY>
- </HTML>
Analyze the result of the run with the values of the three properties:
Nodetype:text_node
NodeType Value: 3
NodeName: #text
NodeValue: Text content//John
Understanding of ELEMENT nodes, attribute nodes, text nodes in the DOM 13.3