getAttribute cannot return class in IE7?

后端 未结 5 1680
暖寄归人
暖寄归人 2021-01-04 18:59

I need to find random nodes according to random attribute values. To do that I use getAtrribute on nodes from getElementsByTagName.

It seems like when I look for cl

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 19:44

    Here you can get and set the class attribute with cross browser compatibility.

          //also works with IE7 and below
    
          //get class attribute value
          var class_name = document.getElementById('elem_id').className;
    
          //set class attribute
          document.getElementById('elem_id').className  = 'new-class-name';
    

提交回复
热议问题