/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getElementsByClassName(className, tag, elm){ var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)"); var tag = tag || "*"; var elm = elm || document; var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag); var returnElements = []; var current; var length = elements.length; for(var i=0; i<length; i++){ current = elements[i]; if(testClass.test(current.className)){ returnElements.push(current); } } return returnElements; }