Skip to content

Instantly share code, notes, and snippets.

@kangax
Created July 25, 2010 13:33
Show Gist options
  • Save kangax/489570 to your computer and use it in GitHub Desktop.
Save kangax/489570 to your computer and use it in GitHub Desktop.
var query = (function() {
var query, engine, engines = ('NW.Dom.select,base2.dom.querySelectorAll,Sizzle,$$,$,jQuery,'+
'YAHOO.util.Selector.query,dojo.query,Ext.DomQuery.select,document.querySelectorAll').split(',');
while (engine = engines.shift()) {
if (Function('try{ var els = ' + engine + '("*"); return els.length > 0 }catch(e){}')()) {
query = Function('cssExpr', 'return ' + engine + '(' +
(/^base2/.test(engine) ? 'document,' : '') + 'cssExpr)');
break;
}
}
return function(cssExpr) {
var elements = query(cssExpr), i, result = [ ];
if (elements && (i = elements.length)) {
while (i--) {
result[i] = elements[i];
}
}
return result;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment