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