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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:19:34+00:00 2026-05-29T22:19:34+00:00

In several jquery tutorials, separate ID and Class are used for JS and CSS

  • 0

In several jquery tutorials, separate ID and Class are used for JS and CSS. for example

<div id="test" class="test">TEST</div>

As ID is used in the jQuery code, and Class is used in CSS. To me it is easier to not introduce Class and use ID for CSS rule too. Is there any advantage to use css-less ID for javascript?

EDIT: Thanks folks! I know the difference between ID and Class; I am asking why some use separate ID and Class for JS and CSS when one is sufficient. Here, the matter is the necessity for uniqueness of ID. The case is separating JS and CSS tasks (while they are closely entangled).

EDIT2: As requested, I give a typical example: this Tutorial. Look for actionsBox; .actionsBox has been used for CSS and #actionsBox for JS. As you can see there is only one <div> so ID would be enough for styling.

  • 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-29T22:19:34+00:00Added an answer on May 29, 2026 at 10:19 pm

    Edit: @Sharon commented a link to a great article that discusses the drawbacks of using id selectors in CSS.

    One reason people might only use classes in CSS is the specificity of the id selector.

    If you’ve got two style declarations for one element, and they specify different values for a property, then the style declaration with the more specific selector wins out.

    For example:

    HTML

    <div id="test" class="special-test"></div>
    

     CSS

    #test {
        color: red;
    }
    
    .special-test {
        color: blue;
    }
    

    The ID selector trumps all other selectors for specificity (see http://www.w3.org/TR/selectors/#specificity for the rules), so here, the <div> will be red.

    People who added class="test" to the <div> would presumably have written this:

    HTML

    <div id="test" class="test special-test"></div>
    

     CSS

    .test {
        color: red;
    }
    
    .special-test {
        color: blue;
    }
    

    When both style declarations have selectors with the same specificity, the later declaration wins out, so here the <div> would be blue.

    Personally, I’ve never found that to be a problem. In the first example, all you have to write to make the <div> blue is this:

    #test.special-test {
        color: blue;
    }
    

    But I guess some people find this aspect of specificity unnecessarily complex, and so avoid it by only using class selectors in their CSS.

    (And I assume they keep the id because it’s faster to retrieve a DOM element in JavaScript by id than by class.)

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

Sidebar

Related Questions

I use several jquery plugins on my website, most of which are actually used
i have the following jquery code. basically i will have several overlapped divs and
Another jQuery issue... I have tried this several times using class and id elements
I use several jquery ui dialogs in my application to collect input from users
I have several jQuery functions on my website but not on every page all
There are several advanced jQuery plugins which filter <div> s by corresponding id or
I have been reading several jQuery tutorials on the web. They all seem very
I have looked at several tutorials involving rails 3 and jquery. The tutorial at
I want to use the jquery autocomplete plugin across several input boxes. In order
I was reading the http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery . And got confused with use of this in

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.