Change CSS of class in Javascript?

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

    Best way to do it is to have a hidden class, like so:

    .hidden { display: none; }
    

    After that, there is a className attribute to every element in JavaScript. You can just manipulate that string to remove occurrences of the hidden class and add another one.

    One piece of advice: Use jQuery. Makes it easier to deal with that kind of stuff, you can do it like:

    $('#element_id').removeClass('hidden').addClass('something');
    

提交回复
热议问题