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