Skip to content

Instantly share code, notes, and snippets.

@m1el
Created September 30, 2013 09:39
Show Gist options
  • Save m1el/6761486 to your computer and use it in GitHub Desktop.
Save m1el/6761486 to your computer and use it in GitHub Desktop.
function $x(xpath, root) {
root = root ? root : document;
try {
var nodes = document.evaluate(xpath, root, null, 7, null);
} catch(e) {
return [];
}
var result = [];
for(var i = 0; i < nodes.snapshotLength; i++) {
result[i] = nodes.snapshotItem(i);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment