如何使用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');