JavaScript: Node value

By Xah Lee. Date: . Last updated: .
node.nodeValue
Return the content of text node, as string. (Node Type 3.) For most other node types, it returns null.

As of 2012-04-29, this works in all major browsers.

<div id="xc5069">abc <b>xyz</b></div>
abc xyz
const xx = document.getElementById("xc5069").childNodes[0].nodeValue;
console.log( xx === "abc " );

To change a HTML element's content, you can set nodeValue to some text. See: Change Element's Content .

Tip:

nodeValue is most useful if you are working in XML, or you need to work on Whitespace Nodes.

If you are working with HTML for websites, it's more practical and convenient to use textcontent or innerHTML property. [see DOM: textContent, innerHTML, innerText, nodeValue]

JavaScript/DOM: Node Name, Node Type, Node Value

BUY
Ξ£JS
JavaScript in Depth

DOM Scripting

Overview

DOM Methods

Basic Examples

HTML Input

Web Scripting Examples

Web Scripting Misc