HTML DOM nodeValue Property
Example
Return the node value of the first <button> element in the document:
document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;
Try it Yourself »
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:
node.nodeValue
Set the node value:
node.nodeValue = value
Property
Pryperty | Description |
value | The node value. |
Return Value
Type | Description |
String | The node 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:
const x = document.getElementById("myDIV").firstChild;
let text = "";
text += "Name: " + x.nodeName + "<br>";
text += "Value: " + x.nodeValue + "<br>";
text += "Type: " + x.nodeType;
Try it Yourself »
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 |