/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
document.getElementsByClassName = function(searchClass, node, tag){ var classElements = []; node = node || document; var pattern = new RegExp('(^|\\s)' + searchClass+ '(\\s|$)'); var els = (!tag && node.all) || node.getElementsByTagName(tag || '*'); var elsLen = els.length; for (var i=0, j=0;i<els.length;i++) { if (pattern.test(els[i].className)) { classElements[j] = els[i]; j++; } } return classElements; }