0

Possible Duplicate:
jQuery create CSS rule / class @ runtime

Is it possible to create & delete css classes with jQuery?

Please note I'm not talking about addClass and removeClass. I actually want to write a new class and delete old classes with jQuery.

The reason I ask is because I have a ton of animations that I'm trying to convert to CSS3 transitions. It gets a little hairy because the initial height I set is dynamic, so I'm currently trying to change the classes from a class without transitions to one with transitions.

The problem is that CSS is so much faster than jQuery that even though I set the CSS setting first and then switch the classes, the new CSS setting is actually applied after the classes are switched (love transitions for that).

So, I'd like to dynamically create classes & add them then remove them & delete them.

If this isn't possible, does anyone know how to get around my dynamic CSS setting problem?

Community
  • 1
  • 1

1 Answers1

1

You can add a new element to the html document:

$("<style type='text/css'> .myclass{ color:#000; border:1px solid #000;} </style>").appendTo("head");

But I don't think it is possible to directly attach it to an external css-file.

Sven Bieder
  • 5,515
  • 2
  • 21
  • 27
  • that's great! is it possible to delete it? –  Jan 14 '13 at 19:01
  • 1
    @JoeCoderGuy It is not directly possible to delete a class from the ` – Sven Bieder Jan 14 '13 at 19:09
  • would you mind adding that knowledge to ur a for check? thank-you! –  Jan 28 '13 at 03:35