在Javascript中改变类的CSS? [英] Change CSS of class in Javascript?
问题描述
我有一个类的显示设置为无
我想在Javascript现在设置为 inline
我知道我可以用一个id与 getElementById
,但什么是最干净的方式来做一个类?
实际上更改与类关联的样式规则 —使用 styleSheets
数组( MDC链接, MSDN链接),但坦率地说,你可能更好(作为changelog说)有一个单独的样式,定义 display:none
,然后当你希望它们不再被隐藏时,从元素中删除该样式。
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?
You can do that — actually change style rules related to a class — using the styleSheets
array (MDC link, MSDN 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.
这篇关于在Javascript中改变类的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!