/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getElementsByClass( searchClass, domNode, tagName) { if (domNode == null) domNode = document; if (tagName == null) tagName = '*'; var el = new Array(); var tags = domNode.getElementsByTagName(tagName); var tcl = " "+searchClass+" "; for(i=0,j=0; i<tags.length; i++) { var test = " " + tags[i].className + " "; if (test.indexOf(tcl) != -1) el[j++] = tags[i]; } return el;
URL: http://www.anyexample.com/webdev/javascript/javascript_getelementsbyclass_function.xml