JavaScript access CSS class by its name?

后端 未结 6 1829
难免孤独
难免孤独 2021-01-12 16:33

I have to access CSS class by name, and the code below works. However if I try hui[\"myclass\"] or hui[\".myclass\"] instead of hui[0]

6条回答
  •  不知归路
    2021-01-12 16:45

    (document.styleSheets[0].cssRules || document.styleSheets[0].rules)[0].style.color = '#ff0000' should work.

    Quirksmode CSSOM (DOM CSS) compatibility table

提交回复
热议问题