Home > Web Front-end > JS Tutorial > body text

How to Implement the getElementsByClassName() Method in Older Internet Explorers?

Susan Sarandon
Release: 2024-10-22 07:32:02
Original
887 people have browsed it

How to Implement the getElementsByClassName() Method in Older Internet Explorers?

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;
}; 
Copy after login

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!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!