English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM nodeValue Property

HTML DOM Element Object

nodeValueAttribute returns or sets the value of the current node.

For text, comment, and CDATA nodes, nodeValue returns the content of the node.

For attribute nodes, it will return the value of the attribute.

nodeValue property can be used as an alternative methodtextContentAttribute.

Syntax:

Return node value:

node.nodeValue

Set node value:

node.nodeValue = newValue
var x = document.getElementById("myPara").firstChild.nodeValue;
Test and See‹/›

Browser Compatibility

All browsers fully support the nodeValue attribute:

Attribute
nodeValueIsIsIsIsIs

Attribute Value

ValueDescription
newValueSpecify the node value of the specified node

Technical Details

Return value:A string representing the node's value.
Possible values:
  • Returns for element node and document nodenull

  • Return the attribute node's attribute value

  • Return the content of the text node

  • Return the content of the comment node

DOM Version:DOM Level1

More examples

Set the node value of an element in the document:

document.getElementById("myPara").firstChild.nodeValue = "HELLO WORLD";
Test and See‹/›

Return the node name, node type, and node value of the first child of the div element:

<div id="div-1">This is a div element.</div>
<script>
var x = document.getElementById("div-1).firstChild;
var txt = "";
txt += "The node name: " + x.nodeName + "<br>";
txt += "The node value: " + x.nodeValue + "<br>";
txt += "The node type: " + x.nodeType;
document.getElementById("para").innerHTML = txt;
</script>
Test and See‹/›

Related References

HTML DOM Reference:node .nodeName property

HTML DOM Reference:node .nodeType property

HTML DOM Reference:node .childNodes property

HTML DOM Element Object