Node properties
In the Document Object Model (DOM), each node is an object. The DOM node has three important properties:
1. NodeName: Name of the node
2. NodeValue: The value of the node
3. NodeType: Type of node
One, NodeName property: The name of the node, is read-only.
1. The nodeName of the element node is the same as the label name
2. The nodeName of the attribute node is the name of the property
3. The nodeName of a text node is always #text
4. The nodeName of the document node is always #document
Second, NodeValue property: The value of the node
1. The nodevalue of the element node is undefined or null
2. Text node NodeValue is the text itself
3. The nodevalue of the attribute node is the value of the property
nodeType attribute: The type of the node, which is read-only. Here are some common types of nodes:
Element type node type
Element 1
Property 2
Text 3
Note 8
Document 9
Example: Get all the LI tags and output the name of the corresponding node, the value of the node, and the type of the node.
<! DOCTYPE html>
<meta http-equiv=" Content-type "content=" text/html; Charset=utf-8
<title> node properties </title>
<body>
<ul>
<li>javascript</li>
<li>html/css</li>
<li>jQuery</li>
</ul>
<script Type= "Text/javascript";
var node=document.getelementsbytagname ("Li"); //Get Li tags
for (Var i=0;i<node.length;i++)
{
document.write ("li[" + (i+1) + "]:" + "<br/>" + "node Name:" +node[i].nodename+ "<br/>");
document.write ("Node value:" +node[i].nodevalue+ "<br/>");
document.write ("Node type:" +node[i].nodetype+ "<br/><br/>");
}//Output All LI element node properties
</script>
</body>
Output Result:
- Javascript
- Html/css
- Jquery
LI[1]:
Node Name: LI
Node value: null
Node Type: 1
LI[2]:
Node Name: LI
Node value: null
Node Type: 1
LI[3]:
Node Name: LI
Node value: null
Node Type: 1
Note: The tag name of the XML element contained in NodeName is always capitalized!!!
JavaScript Node Properties