Created
April 8, 2021 22:22
-
-
Save ticky/c346aedf0704fe0a5757240a8b41a174 to your computer and use it in GitHub Desktop.
XPath query to array result shorthand function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Looks up an XPath node selector and returns an array of matching nodes | |
const xpathQuerySelector = (xpath) => { | |
var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE); | |
return Array.from({ length: result.snapshotLength }, (_, index) => result.snapshotItem(index)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment