Skip to content
Advertisement

Change CSS of class in Javascript?

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 with getElementById but what’s the cleanest way to do it with a class?

Advertisement

Answer

You can do that — actually change style rules related to a class — using the styleSheets array (MDN link), but frankly you’re probably better off (as changelog said) having a separate style that defines the display: none and then removing that style from elements when you want them no longer hidden.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement