For beginners, the functions and values of the three attributes nodeName, nodeValue and nodeType in HTML DOM are not very clear. The information compiled below contains detailed information about the nodes for reference.
Each node has attributes that contain some information about the node. These properties are:
nodeName (node name) nodeValue (node value) nodeType (node type)
The nodeName attribute contains the name of a node.
The nodeName of the element node is the tag 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 in nodeName is always uppercase.
For text nodes, the nodeValue attribute contains the text.
For attribute nodes, the nodeValue attribute contains the attribute value.
The nodeValue attribute is not available for document nodes and element nodes.
The nodeType attribute returns the type of node.
The most important node types are:
元素 | 1 |
属性 | 2 |
文本 | 3 |
注释 | 8 |
文档 | 9 |