JS: Node value
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 xyzconst 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: 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.
γsee DOM: textContent, innerHTML, innerText, nodeValueγ