Skip to content

Instantly share code, notes, and snippets.

@garann
Created June 21, 2011 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save garann/1038401 to your computer and use it in GitHub Desktop.
Save garann/1038401 to your computer and use it in GitHub Desktop.
seems like there's a more efficient way of doing this..
getEl = function (selector) {
if (document.querySelectorAll) {
return document.querySelectorAll(selector);
} else {
if (selector.indexOf("#") > -1) {
return document.getElementById(selector);
} else {
var sParts = selector.split("."),
tags = document.getElementsByTagName(sParts[0]),
matches = [];
for (var i=0, l=tags.length; i<l; i++) {
var classes = tags[i].className.replace(" ","|") + "|";
if (classes.indexOf(sParts[1]+"|") > -1)
matches.push(tags[i]);
}
return matches;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment