<div id="d1">Hello world</div>
<!-- Example of comment -->
<output id="result">Not calculated yet.</output>Node: nodeValue property / notebook
Node: nodeValue property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
let node = document.querySelector("body").firstChild;
let result = "Node names are:\n";
while (node) {
result += `Value of ${node.nodeName}: ${node.nodeValue}\n`;
node = node.nextSibling;
}
const output = document.getElementById("result");
output.innerText = result;