Change CSS of class in Javascript?

前端 未结 8 727
春和景丽
春和景丽 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:37

    Do you mean something like this?

    var elements = document.getElementsByClassName('hidden-class');
    for (var i in elements) {
      if (elements.hasOwnProperty(i)) {
        elements[i].className = 'show-class';
      }
    }
    

    Then the CSS

    .hidden-class { display: none; }
    .show-class { display: inline; }
    

提交回复
热议问题