Skip to content

Instantly share code, notes, and snippets.

@os0x
Forked from cho45/dollarX.js
Created November 27, 2008 04:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save os0x/29681 to your computer and use it in GitHub Desktop.
Save os0x/29681 to your computer and use it in GitHub Desktop.
very simple $X
// very simple version of $X
// $X(exp);
// $X(exp, context, resolver, XPathResult.NUMBER_TYPE).numberValue;
// @source https:/raw.github.com/gist/29681
function $X (exp, context, resolver, result_type) {
context || (context = document);
var Doc = context.ownerDocument || context;
var result = Doc.evaluate(exp, context, resolver, result_type || XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (result_type) return result;
for (var i = 0, len = result.snapshotLength, res = new Array(len); i < len; i++) {
res[i] = result.snapshotItem(i);
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment