changing CSS class definition

css, javascript, jquery

Solution

Actually altering your stylesheet is pretty challenging. Much more easily, though, you can switch out your stylesheet for a different one, which may be sufficient for your purposes. See How do I switch my CSS stylesheet using jQuery?.

For actually altering the stylesheet content, How to change/remove CSS classes definitions at runtime? will get you started.

Problem

Suppose I have this class: ``` .MyClass{background:red;} ``` This class applies to several divs. I want to change the color of the background to orange by changing the color defined in MyClass. Now, I know I could do `$('.MyDiv').css('background', 'orange');` But my question is really this: how do I change the CSS class definition so that MyClass elements now have `background:orange;`? I want to be able to change several CSS color properties from one color to another. Thanks.

Original source

Related problems