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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian TaoSenior Business Solutions ConsultantCommented:
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)
elepilAuthor Commented:
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.
Brian TaoSenior Business Solutions ConsultantCommented:
Ah, sorry for the miss-reading.  To create the style on the fly and apply it to an element, here's what you need (use .css() method):
var someStyle={
    "color": "yellow",
    "background": "red",
    "border": "1px solid blue"

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
Exactly what I was looking for, thanks much, Brian!
Brian TaoSenior Business Solutions ConsultantCommented:
Glad to help.  Thanks for the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.