<div>XPath example</div>
<p>Iterator state: <output></output></p>XPathResult: invalidIteratorState property / notebook
XPathResult: invalidIteratorState 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.ANY_TYPE,
null,
);
// Invalidates the iterator state
document.querySelector("div").remove();
document.querySelector("output").textContent = result.invalidIteratorState
? "invalid"
: "valid";