Link to home
Start Free TrialLog in
Avatar of elepil
elepil

asked on

jQuery question about .css()

Is there a way for me to create something like this in jQuery during RUNTIME, i.e., ON THE FLY:

.someStyle {
    color: yellow;
    background: red;
    border: 1px solid blue;
}

Open in new window


and then be able to reference the whole set of styles as .addClass(".someStyle")?

In other words, I don't want to have to do it this way: $("#someElement").css("color", "yellow"), and so on.

Thanks.
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Yes, just use $("#someElement").addClass("someStyle");
Please note when you use addClass the parameter is the class name and not a class selector (means no need for the dot)
Avatar of elepil
elepil

ASKER

Brian, thanks for responding, but I don't think you read my question carefully.

Notice I bold-faced RUNTIME and ON THE FLY.

I wanted to know if there was a way to still use addClass("someStyle") that somehow represents CSS styles created entirely within jQuery and not something defined in an external style sheet or within a <style> tag.
ASKER CERTIFIED SOLUTION
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elepil

ASKER

Exactly what I was looking for, thanks much, Brian!
Glad to help.  Thanks for the points.