//Returns true
console.log(document.evaluate('//a[@id="next"]/@href', document,
null, XPathResult.ANY_TYPE, null).iterateNext() instanceof Attr);
//Returns "?page=3"
console.log(document.evaluate('//a[@id="next"]/@href', document,
null, XPathResult.ANY_TYPE, null).iterateNext().value);
//Returns true
console.log(document.evaluate('//a[@id="next"]', document,
null, XPathResult.ANY_TYPE, null).iterateNext() instanceof Node);
//Returns false
console.log(document.evaluate('//a[@id="next"]', document,
null, XPathResult.ANY_TYPE, null).iterateNext() instanceof Attr);
//Returns true
console.log(document.evaluate('//a[@id="next"]', document,
null, XPathResult.ANY_TYPE, null).iterateNext().nodeType === Node.ELEMENT_NODE);
//Returns "Next"
console.log(document.evaluate('//a[@id="next"]', document,
null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
//Returns true
console.log(document.evaluate('//a[@id="next"]/text()', document,
null, XPathResult.ANY_TYPE, null).iterateNext() instanceof Node);
//Returns true
console.log(document.evaluate('//a[@id="next"]/text()',
document, null, XPathResult.ANY_TYPE, null).iterateNext().nodeType === Node.TEXT_NODE);
//Returns "Next"
console.log(document.evaluate('//a[@id="next"]/text()', document,
null, XPathResult.ANY_TYPE, null).iterateNext().nodeValue);
<!DOCTYPE html>
<html>
<body>
<a href="?page=3" id="next">Next</a>
</body>
</html>