Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7957347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:14:13+00:00 2026-06-04T04:14:13+00:00

Here are a couple ways to apply CSS styling to an element using jQuery

  • 0

Here are a couple ways to apply CSS styling to an element using jQuery that we’re all familiar with:

$('.box').css({'background':'#fff', 'color':'#000'});

Or, we can use a combination of jQuery and external CSS to elicit the same effect:

.box.deco { background:#fff; color:#000; }

...

$('.box').addClass('deco');

Ignoring the fact that having CSS styles living in JS code is evil (IMHO), I’m left wondering after all the years I’ve been doing this: which approach is more efficient? I’m working on task right now that will be doing a relatively massive amount of this type of style manipulation across multiple DOM elements, and in this case the performance is worth the consideration.

I did look around at other similar questions on SO but didn’t find an answer. Care to weigh in?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:14:14+00:00Added an answer on June 4, 2026 at 4:14 am

    The most efficient way to to have an existing class name in your CSS and just swap the class name.

    See: Reflows & Repaints: CSS Performance making your JavaScript slow?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here the total height of all <div> 's are 900 pixels, but the jQuery
i see a couple of questions on here and elsewhere that address this in
Here's the background, I have a webservice from a vendor/partner that returns a large
Here's the problem: I have couple of pages which gets its content from a
Firstly here is my ruby and rails version with a couple of the important
I've seen a couple of SQLite performance questions here on Stackoverflow, but the focus
I have seen a couple of question regarding creating datasets in DbUnit here on
I just found Dean Edwards javascript packer here: http://dean.edwards.name/packer/ It has a couple of
The current form is here . It is not complete, and only a couple
I could really do with some help here. I've spent the past couple of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.