Search code examples
javascriptcssdhtml

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 lot 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.


Solution

  • You can add style rules to your stylesheets dynamically:

    IE: addRule
    Others: insertRule