HTML DOM nodeValue Property

Element Object


Get the node value of the first <button> element in the document:

var x = document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;
Try it Yourself »

More "Try it Yourself" examples below.

Definition and Usage

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.

Browser Support

nodeValue Yes Yes Yes Yes Yes


Return the node value:


Set the node value:

node.nodeValue = value

Property Values

Value Description
value  Specifies the node value of the specified node

Technical Details

Return Value: A String, representing the value of the node.

Possible values:

  • Returns null for element nodes and document nodes
  • Returns the value of the attribute for attribute nodes
  • Returns the content for text nodes
  • Returns the content for comment nodes
DOM Version Core Level 1 Node Object

More Examples


Get the node name, node value and the node type of the <div> element's first child node:

<div id="myDIV">This is a div element.</div>

var x = document.getElementById("myDIV").firstChild;
var txt = "";
txt += "The node name: " + x.nodeName + "<br>";
txt += "The node value: " + x.nodeValue + "<br>";
txt += "The node type: " + x.nodeType;
Try it Yourself »

Related Pages

HTML DOM reference: node.nodeName Property

HTML DOM reference: node.nodeType Property

HTML DOM reference: node.nodeValue Property

HTML DOM reference: node.childNodes Property

Element Object