Skip to content

Instantly share code, notes, and snippets.

@nonowarn
Created January 30, 2011 11:01
Show Gist options
  • Save nonowarn/802783 to your computer and use it in GitHub Desktop.
Save nonowarn/802783 to your computer and use it in GitHub Desktop.
(function (win, doc) {
var by = {}, slice = [].slice, type2method = {
id: "getElementById",
className: "getElementsByClassName",
tagName: "getElementsByTagName",
query: "querySelectorAll"
};
for (var type in type2method) if (type2method[type] in doc) (function (type, method) {
by[type] = method.match(/(?:Elements|All)/) ? function () {
return slice.call(doc[method].apply(doc, arguments));
} : function () {
return doc[method].apply(doc, arguments);
};
})(type, type2method[type])
win.by = by;
})(window, document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment