Gets or sets the value of a Node, if the type of Node supports it.
Syntaxvar value = node.nodeValue;
node.nodeValue = newValue;
Return Value
Returns an object of type StringString
The value of the node.
ExamplesThe following code example alters the text of the specified list item by setting the nodeValue property of the text node that is contained by that list item.
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script>
function changeValue(list, itemIndex, newValue) {
if (list.nodeName !== "UL" && list.nodeName != "OL")
return false;
if (itemIndex > list.childNodes.length -1)
return false;
var liElements = list.childNodes[itemIndex];
if (!liElements)
return false;
var textNode = liElements.childNodes[0];
if (textNode.nodeType !== 3)
return false;
textNode.nodeValue = newValue;
return true;
}
function initialize() {
document.getElementById("list").addEventListener(
"click",
function () {
changeValue(this, 0, "New Node value");
},
false);
}
document.addEventListener("DOMContentLoaded", initialize, false);
</script>
</head>
<body>
<ul id="list"><li>Old Node Value</li></ul>
</body>
Usage
Use this property to get or set the value of a Node. The concept of nodeValue changes between the various Node types (Element, Text and the rest).
Notes
null
. Use Node.nodeName to get their name or dom/Node/textContent to get all of the text included in their tree.Mozilla Developer Network : [Node.nodeValue Article]
Microsoft Developer Network: [nodeValue Property Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4