javascript document.getElementsByClassName compatibility with IE

前端 未结 7 657
逝去的感伤
逝去的感伤 2020-11-22 08:44

What is the best method to retrieve an array of elements that have a certain class?

I would use document.getElementsByClassName but IE does not support it.

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 09:06

    function _getClass(whatEverClasNameYouWant){
    var a=document.getElementsByTagName('*');
       for(b in a){
          if((' '+a[b].className+' ').indexOf(' '+whatEverClasNameYouWant+' ')>-1){
          return a[b];
          }
       }
    }
    

提交回复
热议问题