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 326069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:16:31+00:00 2026-05-12T09:16:31+00:00

With MVC and jQuery I am making significantly more use of CSS. A question

  • 0

With MVC and jQuery I am making significantly more use of CSS. A question that came to mind is what is the best approach for using Element IDs vs. Classes. If I use Element IDs the selectors in jQuery are shorter. For example:

#imageTag... $('#imageTag')
#searchTag... $('#searchTag')

As an alternative it could be structured with a parent container element.

#searchTool, #classifyTool .tag

In this case selectors such as

$(‘#searchTool .tag’) or $(‘#classifyTool .tag’)

could be used. This approach can be particularly useful when there are multiple instances of a class throughout the page, e.g., .tag. You just change the parent container object.

This is just a simple theoretical example and is not intended to represent real styles, just portray the concept.

So there are two questions:

  1. Is there any impact on performance of either the page/CSS or jQuery assuming there are a large # of styles on a page?

  2. The second approach seems more flexible and maintainable. Thoughts based upon your experiences.

Is there a better alternative approach?

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-05-12T09:16:31+00:00Added an answer on May 12, 2026 at 9:16 am
    • IDs are the fastest
    • Tag names are next fastest
    • Class names with no tag name are the slowest

    As for which one to use, use whichever is most appropriate. If you have a search box on your page then using an ID for that would be most appropriate because there’s only one search box. Table rows on the other hand will probably be identified by class because there is (or can be) more than one.

    Try not to use selectors (in CSS or jQuery) like “.class”. You’re forcing jQuery or the browser to basically traverse the entire document tree. Most of the time the class will only apply to one kind of tag so specify that (eg “div.class”). That alone can make a huge performance difference (particularly on jQuery with a large document).

    The length of the selector should not be a consideration. Performance, readability and maintainability should be.

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

Sidebar

Related Questions

Using ASP.NET MVC + jQuery : I need to use some values owned by
I am developing an application using Asp.net mvc and jquery. I'd like to use
So I'm using jqGrid with my mvc.net / Ling2Sql prototype site that I'm making
Please keep in mind that I'm rather new to how MVC, Json, jQuery, etc.
I have to build a registration form using asp.net mvc 3 jquery validate. That
-- Running within ASP.NET MVC alongside jQuery -- I'm using jQuery to render a
I'm using Spring MVC and jquery autocomplete, my spring controller looks like this @RequestMapping(value
I am using asp.net mvc and jquery to make ajax requests and when the
I have build a webapplication using ASP.NET MVC and JQuery. On my local machine
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic

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.