The getElementsByClassName() is already present in some modern browsers, but this code from Kevin Yank at Sitepoint just adds it for those browsers that don’t already have it….
function getElementsByClassName(className) { // get all elements in the document if (document.all) { var allElements = document.all; } else { var allElements = document.getElementsByTagName("*"); } var foundElements = []; for (var i = 0, ii = allElements.length; i < ii; i++) { if (allElements[i].className == className) { foundElements[foundElements.length] = allElements[i]; } } return foundElements; }
Main Category