MDN self-hosted library · e01.org

XPathResult: stringValue property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<div>XPath example</div>
<div>Text content of the &lt;div&gt; above: <output></output></div>
js
const xpath = "//div/text()";
const result = document.evaluate(
  xpath,
  document,
  null,
  XPathResult.STRING_TYPE,
  null,
);
document.querySelector("output").textContent = result.stringValue;