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

  • SEARCH
  • Home
  • 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 1096331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:16:06+00:00 2026-05-17T00:16:06+00:00

There’s quite a few questions on Stack Overflow about id vs class but these

  • 0

There’s quite a few questions on Stack Overflow about id vs class but these questions are nearly always in relation to CSS – and the generally accepted answer is to use classes to style a particular set of elements, and ids for specific instances. Makes sense, fair enough.

I’m finding however that as I do more and more Javascript/jQuery/ajax, that approach is starting to become less clear cut and I’m finding situations where semantically elements should be given ids, but because there could be multiple instances I’m supposed to use classes.

Here’s an example of what I mean:

Take a look at the toolbar on Stack Overflow’s markdown question editor – each button has an ID to uniquely identify it. Makes perfect sense – it’s one button that performs a specific function and there’s probably script hooked to it based on that id.

Now imagine that I’m building a rich web app and there’s a page that has two tabs each with a markdown editor on it. Does this mean that the toolbar buttons should now be using classes to identify them?

This just seems wrong.

Another example: I’m working on a photo gallery site that has a little toolbar overlaid on each photo. Convention says that because there’s multiple instances of these buttons I should use classes. Really?

So my questions are….

  • If I commit the crime of duplicate IDs on a page, which browsers will actually break?
  • For browsers where this does break, is it just the CSS styling that will break, or will jQuery selectors also break.
  • Is it really so bad to use duplicate ids in cases like those described.
  • 1 1 Answer
  • 1 View
  • 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-17T00:16:06+00:00Added an answer on May 17, 2026 at 12:16 am

    Classes mean is a … (indefinite) IDs mean is the … (definitive)

    “This div is a photo-toolbar. There can be more like it.” Makes sense, I would use a class.

    I wouldn’t necessarily ID toolbar buttons, unless I was sure that there can only be one instance of that toolbar on the page. In the case with StackOverflow’s markdown editor, I also think these should be classes for more flexibility (the whole editor can be wrapped in a unique ID, like #answer-editor, or #comment-editor) instead.

    Browsers are quite flexible in what they accept, but that doesn’t mean the standards should be broken.

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

Sidebar

Related Questions

There are nice SO question and answers about this issue, but these options didn't
There's a few previous questions on StackOverflow questioning how one goes about accessing local
There are many questions about this PersistenceException, but I have not seen some, where
There are a lot of questions about full-joining in mysql(5.1.36). Of course the solution
There have been multiple questions regarding this topic but I have never really settled
There are many tutorials that talk about deleting index.php from the url. But I
There are a few ways to get class-like behavior in javascript, the most common
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There was a similar question posted asking in general about alternatives to Qt. Well,
There is any way to set the generic type (T) of class in the

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.