开发者

Changing class styles dynamically without a loop

Is it possible to change the style of a class via JavaScript without looping through existing elements which have that class applied to them? Since my page uses a lo开发者_StackOverflow中文版t of DHTML, this method would prove ineffective when creating elements.

I've searched and have only found the answers "no" and "loop", but I feel that the styleSheet object must be able to do something along these lines. If not, however, I will accept that, but first I want to ask here where people are most likely to know the final answer.

Thanks for all answers.


You can add style rules to your stylesheets dynamically:

IE: addRule
Others: insertRule


Use jQuery, with this one line:

 $('.className').css("attrib", "value");

It will change the value of all elements with class = className.

Refer: http://api.jquery.com/css/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜