Change CSS of class in Javascript?

前端 未结 8 752
春和景丽
春和景丽 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条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 18:16

    To change CLASS you need to edit document stylesheets

    [...document.styleSheets[0].cssRules].find(x=> x.selectorText=='.box')
        .style.display='inline';
    

    [...document.styleSheets[0].cssRules].find(x=> x.selectorText=='.box')
        .style.display='inline';
    .box {
      margin: 10px;
      padding: 10px;
      background: yellow;
      display: none
    }
    My box 1
    My box 2
    My box 3

提交回复
热议问题