Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  178] [ 3]  / answers: 1 / hits: 36377  / 15 Years ago, wed, april 8, 2009, 12:00:00

I know it is possible to add new CSS classes definitions at runtime through JavaScript. But...


How to change/remove CSS classes definitions at runtime?


For instance, supose a I have the class below:


<style>
.menu { font-size: 12px; }
</style>

What I want is, at runtime, change the font-size rule of the .menu class, so that every element in the page who uses this class will be affected.


And, I also want to know how to remove the .menu class definition.


More From » css

 Answers
251

It's not difficult to change CSS rules at runtime, but apparently it is difficult to find the rule you want. PPK has a quick tour of this on quirksmode.org.



You'll want to use document.styleSheets[i].cssRules which is an array you need to parse through to find the one you want, and then rule.style.setProperty('font-size','10px',null);


[#99729] Thursday, April 2, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taylert

Total Points: 627
Total Questions: 91
Total Answers: 108

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
taylert questions
;