Skip to content

Instantly share code, notes, and snippets.

@devongovett
Created August 13, 2011 21:10
Show Gist options
  • Save devongovett/1144257 to your computer and use it in GitHub Desktop.
Save devongovett/1144257 to your computer and use it in GitHub Desktop.
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment