<div>XPath example</div>
<div>Text content of the <div> above: <output></output></div>XPathResult: stringValue property / notebook
XPathResult: stringValue property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const xpath = "//div/text()";
const result = document.evaluate(
xpath,
document,
null,
XPathResult.STRING_TYPE,
null,
);
document.querySelector("output").textContent = result.stringValue;