使用JQuery添加到css类 [英] Add to a css class using JQuery

查看:154
本文介绍了使用JQuery添加到css类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用JQuery添加/更新css类。

Is it possible to add/update a css class using JQuery.

我知道我可以使用使用jquery 添加css规则,但我想从css类本身添加/删除。

I know I can add css to a DOM element using this add css rule using jquery, but I would like to add/remove from the css class itself.

推荐答案

您不能使用jQuery直接在单独的css文件中更新CSS类。然而,您可以创建< style> 标记并添加/覆盖CSS类:

You cannot directly update the CSS classes in a separate css file with jQuery. You could however create a <style> tag and add/overwrite a CSS class:

$('<style>.newClass { color: red; }</style>').appendTo('body');

更新CSS类时,您需要注意级联顺序。否则,它可能不会证明是你的后果。

When updating a CSS class, you'll need to take care the cascading order. Otherwise, it may not turn out to be the effect you are after.

这篇关于使用JQuery添加到css类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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