Change CSS of class in Javascript?

前端 未结 8 731
春和景丽
春和景丽 2020-12-01 17:53

I\'ve got a class with the display set to none I\'d like to in Javascript now set it to inline I\'m aware I can do this with an id wit

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 18:17

    You can use getElementsByClassName in which you'll get an array of elements. However this is not implemented in older browsers. In those cases getElementsByClassName is undefined so the code has to iterate through elements and check which ones have the desired class name.

    For this you should use a javascript framework such as jQuery, mootools, prototype, etc.

    In jQuery it could be done with a one-liner as this:

    $('.theClassName').css('display', 'inline')
    

提交回复
热议问题