Is it possible to modify the properties of a CSS class, rather than the element properties, using jQuery?
Here's a practical scenario:
I have a div with the class red
.red {background: red;}
I wish to change the background property of the class red
, not all elements currently styled with the red
class.
If I use jQuery's .css() method:
$('.red').css('background','green');
it will update the background color for existing elements with the red
class. So far so good.
However, if I retrieve more divs with the class red
via an Ajax call, those new elements will not have the green background; instead, they'll retain the original red
background.
I could reapply the jQuery .css() method again. But I am curious if there's a way to alter the class itself. Keep in mind that this is just a basic example.