Help us understand the problem. What is going on with this article?

getElementsByClassNameが使えないブラウザで利用する方法

More than 5 years have passed since last update.

getElementsByClassNameが使えないブラウザで利用する場合のコード

すぐ忘れるのでメモ

javascript
if(typeof(document.getElementsByClassName) == "undefined"){
  document.getElementsByClassName = function(t){
    var elems = new Array();
    if (document.all){
      var allelem = document.all;
    } else {
      var allelem = document.getElementsByTagName("*");
    }
    for (var i = j = 0, l = allelem.length; i < l; i++) {
      var names = allelem[i].className.split(/\s/);
      for (var k = names.length - 1; k >= 0; k--) {
        if (names[k] === t) {
          elems[j] = allelem[i];
          j++;
          break;
        }
      }
    }
    return elems;
  };
}
skryoooo
dac
DACは、インターネットに特化したデジタル広告ビジネスを展開しています。インターネット広告に関するサービスを総合的に提供するデジタルエキスパートです。
https://www.dac.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away