Created
March 25, 2012 12:55
-
-
Save stefanocudini/2193492 to your computer and use it in GitHub Desktop.
get element by class name
This file contains 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
function getElementsByClassName(classname, node) { | |
if(!node) node = document.getElementsByTagName("body")[0]; | |
var a = []; | |
var re = new RegExp('\\b' + classname + '\\b'); | |
var els = node.getElementsByTagName("*"); | |
for(var i=0,j=els.length; i<j; i++) | |
if(re.test(els[i].className))a.push(els[i]); | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment