Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created March 17, 2017 18:10
Show Gist options
  • Save lovasoa/bb72af1f0fdd0294b9e8262100e96ff5 to your computer and use it in GitHub Desktop.
Save lovasoa/bb72af1f0fdd0294b9e8262100e96ff5 to your computer and use it in GitHub Desktop.
Simple xpath function for querying the DOM. Takes a string and returns an array of dom nodes.
function xpath(query) {
var arr = [];
var results = document.evaluate(query, document, null, XPathResult.ANY_TYPE, null );
while(r = results.iterateNext()) arr.push(r);
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment