Get the node value of the first <button> element in the document:
The result of x will be:
More "Try it Yourself" examples below.
The nodeValue property sets or returns the node value of the specified node.
If the node is an element node, the nodeValue property will return null.
Note: If you want to return the text of an element, remember that text is always inside a Text node, and you will have to return the Text node's node value (element.childNodes[0].nodeValue).
For other node types, the nodeValue property will return different values for different node types.
Tip: An alternative to the nodeValue property can be the textContent property.
Property | |||||
---|---|---|---|---|---|
nodeValue | Yes | Yes | Yes | Yes | Yes |
Return the node value:
Set the node value:
Value | Description |
---|---|
value | Specifies the node value of the specified node |
Return Value: | A String, representing the value of the node.
Possible values:
|
---|---|
DOM Version | Core Level 1 Node Object |
Get the node name, node value and the node type of the <div> element's first child node:
The result of txt will be:
HTML DOM reference: node.nodeName Property
HTML DOM reference: node.nodeType Property
HTML DOM reference: node.nodeValue Property
HTML DOM reference: node.childNodes Property