<div>XPath example</div>
<div>Number of matched nodes: <output></output></div>XPathResult: snapshotLength property / notebook
XPathResult: snapshotLength 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";
const result = document.evaluate(
xpath,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
document.querySelector("output").textContent = result.snapshotLength;