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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:07:11+00:00 2026-05-26T16:07:11+00:00

I have a checkbox declared in my html like this: <input id=names name=names type=checkbox

  • 0

I have a checkbox declared in my html like this:

<input id="names" name="names" type="checkbox" value="1">One</input>
<input id="names" name="names" type="checkbox" value="2">One</input>
<input id="names" name="names" type="checkbox" value="3">One</input>

I thought $('#names') will give me handle to all the checkbox elements but it doesn’t, however $('input#names') does.

$('#names').length is 1.

and

$('input#names').length is 3

Why is the difference?
jsfiddle: http://jsfiddle.net/Urbw5/8/

Thanks,
Chris.

  • 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-26T16:07:12+00:00Added an answer on May 26, 2026 at 4:07 pm

    The difference is immaterial, id values must be unique within a document. If you need to group the inputs, you’ll have to use something other than id (class is frequently [over]used for this, but you can do it structurally as well — for instance, all input elements within a given container).

    The reason for the difference in the results you’re seeing lies in how jQuery’s selector engine (Sizzle) optimizes. If you pass in a simple ID-based selector, Sizzle uses document.getElementById (and then checks that what it got back really has that id, because of bugs in IE prior to IE8). So it returns one element.

    But if you pass in a compound selector like input#names, it doesn’t follow that optimization path and actually does a DOM search (either directly in its own code, or via document.querySelectorAll if the browser supports it). Usually that involves searching for all matching elements first (e.g., all input elements), and then filtering the list according to the other qualifiers. So it happens that on your test browser, either Sizzle or the browser’s selector engine isn’t short-circuiting that selector even though it should know that having found one matching element, that’s all it needs to do.

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

Sidebar

Related Questions

I have some checkbox that looks like this <%= Html.CheckBox(Remember) %> <%= Html.Label(Remember, Keep
I have this checkBox in my view inside a form: <g:checkBox name=myCheckbox value=${false} />
I have a checkbox in GridViewColumn which i use for show/change database value. The
I have a checkbox who's checked value is bound to a binding source which
I have to copy the text from one text box to another using checkbox
I have this one in View: <% foreach (var item in (List<MyType>)ViewData[MyTypeArray]) { %><tr>
I have a checkbox group which works fine when you tick one but it
I have a checkbox that has this text: I agree to the terms and
I have a checkbox that if checked stores the value testing to the field
i have customized ListBox declared in XAML: <ListBox x:Name=uicMDSQonfServer> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal Margin=0,5,0,5>

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.