JS DOM: Node value

By Xah Lee. Date: . Last updated: .

Method nodeValue

node.nodeValue
  • Return the content of text node, as string. (Node Type 3.)
  • For most other node types, it return null.

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

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

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

πŸ’‘ TIP: Use nodeValue in XML

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.

JS DOM, About Node, Node Type