Created
June 21, 2011 17:35
seems like there's a more efficient way of doing this..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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