在Javascript中改变类的CSS? [英] Change CSS of class in Javascript?

查看:130
本文介绍了在Javascript中改变类的CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类的显示设置为我想在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆