The nodeName, nodeValue, and nodeType properties contain information about nodes.
In the XML DOM, each node is an object.
Objects have methods and properties, that can be accessed and manipulated by JavaScript.
Three important node properties are:
The nodeName property specifies the name of a node.
The nodeValue property specifies the value of a node.
The following code retrieves the text node value of the first <title> element:
var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
var txt = x.nodeValue;
Try it Yourself »
Result: txt = "Everyday Italian"
Example explained:
The following code changes the text node value of the first <title> element:
var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.nodeValue = "Easy Cooking";
Try it Yourself »
Example explained:
The nodeType property specifies the type of node.
nodeType is read only.
The most important node types are:
Node type | NodeType |
---|---|
Element | 1 |
Attribute | 2 |
Text | 3 |
Comment | 8 |
Document | 9 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!