HTML DOM nodeValue Property
Example
Return the node value of the first <button> element in the document:
More examples below.
Description
The nodeValue
property sets or returns the value of a 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.
Alternatives
See Also:
Syntax
Return the node value:
Set the node value:
Property
Return Value
null
for element and document nodes.The attribute value for attribute nodes.
The text content for text nodes.
The text content for comment nodes.
More Examples
Get the node name, value and type of "myDIV"s first child:
let text = "";
text += "Name: " + x.nodeName + "<br>";
text += "Value: " + x.nodeValue + "<br>";
text += "Type: " + x.nodeType;
Browser Support
element.nodeValue
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |