English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
Return node value:
node.nodeValue
Set node value:
node.nodeValue = newValue
var x = document.getElementById("myPara").firstChild.nodeValue;Test and See‹/›
All browsers fully support the nodeValue attribute:
Attribute | |||||
nodeValue | Is | Is | Is | Is | Is |
Value | Description |
---|---|
newValue | Specify the node value of the specified node |
Return value: | A string representing the node's value. Possible values:
|
---|---|
DOM Version: | DOM Level1 |
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‹/›
HTML DOM Reference:node .nodeName property
HTML DOM Reference:node .nodeType property
HTML DOM Reference:node .childNodes property