getElementsByClassName() Method Incompatibility with Older Internet Explorers
The inability of Internet Explorers 6, 7, and 8 to recognize the getElementsByClassName() method generates an error message "Object does not support this method." This query addresses how to select elements by their classes using alternative methods in these browsers.
Solution
For Internet Explorer 6, Netscape 6 , Firefox, and Opera 7 , incorporating the following script will provide compatibility with the getElementsByClassName() method:
document.getElementsByClassName = function(cl) { var retnode = []; var elem = this.getElementsByTagName('*'); for (var i = 0; i < elem.length; i++) { if((' ' + elem[i].className + ' ').indexOf(' ' + cl + ' ') > -1) retnode.push(elem[i]); } return retnode; };
The above is the detailed content of How to Implement the getElementsByClassName() Method in Older Internet Explorers?. For more information, please follow other related articles on the PHP Chinese website!