nodeValue (W3C DOM Core property)

Version Depr. Static Read-only
DOM1 No No No
Browser support (more…)
IE6+ FF1.5+ SA3+ OP9.5+
Full Full Full Full


var value = node.nodeValue;

In the example above, if node is an Attr then the value variable will be the value of the attribute; if node is a Text node it will be the text content; if node is an Element it will be null.

So in the following HTML example, the id attribute has the node value tagline, the text node inside the q element has the node value A Tale of Two Springfields, while the q element itself has a null node value:

<q id="tagline">A Tale of Two Springfields</q>

A common mistake is to think that the text inside an element is that element's node value, but that isn't the case. As we've seen, the element itself has no node value — it has a child text node, and that has a node value equal to its content.

The nodeValue property is read/write — it can be used to set the value as well as get it.


The value of this node — which is the value of an Attr node, the contents of a CDATASection, Comment, ProcessingInstruction or Text node, or null for any other type of node.

This property is read/write.

Tip: This property is more reliable than specialized properties

The nodeValue property is the best way of manipulating the value of nodes - preferable over more specialized properties, such as data or value, because of various browser issues.


Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Partial Full Full Full Full Full Partial Partial Full Buggy Full

Safari 1.3 and 2 in HTML mode1 cannot retrieve the nodeValue of a Comment node, because they cannot see comments at all.

Opera 9.0 in pure XML (but not XHTML mode2) parses entities when setting the nodeValue of an attribute (contrary to the specification).

: IE5.5 cannot retrieve attribute nodes

In Internet Explorer 5.5 in HTML it's only possible to refer to an attribute's value, not to the node itself, however attribute values retrieved through the attributes collection do inherit the nodeName and nodeValue properties. For nodes that are available, this property always returns correctly.


1 On XHTML or HTML pages served as text/html.

2 On XHTML pages served as application/xhtml+xml.

User-contributed notes

There are no comments yet.

Related Products