如何使用jQuery更改多个元素的样式? [英] How can I change the style of multiple elements using jQuery?

查看:104
本文介绍了如何使用jQuery更改多个元素的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSS样式表,有这样的规则:

I have one CSS style sheet with rules like this:

h1, h2, h3, h4, .contentheading, .title{

 font-size: 13px ;
 font-weight: normal;
 font-family: Arial, Geneva, Helvetica, sans-serif ;
}

标签,类是通过插件生成的,所以我不能添加一个类。

The tags, classes are generated by plugin so i can't add a single class to it.

所以,有没有办法,我可以改变所有元素的样式,在运行时,不涉及通过他们一个?

So, is there any way that I can change the styles of all elements at once, at runtime, that doesn't involve going through them one by one?

推荐答案

你可以在jQuery中做多个选择器,就像在Css。也许不是最好的性能,但会工作。

You can do multiple selectors in jQuery just like in Css. Maybe not the best performance-wise but will work.

$('h1, h2, h3, h4, .contentheading, .title').css('color', 'red');
$('h1, h2, h3, h4, .contentheading, .title').addClass('someOtherClass');

这篇关于如何使用jQuery更改多个元素的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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