Bug Tracker

Modify

Ticket #10606 (closed bug: wontfix)

Opened 2 years ago

Last modified 2 years ago

#ID-selector inconsistent

Reported by: pcvandam@… Owned by: pcvandam@…
Priority: low Milestone: None
Component: selector Version: 1.6.4
Keywords: Cc:
Blocking: Blocked by:

Description

In the theoretical case you have multiple elements on a page with the same ID, the following selectors give different results:

$('#id') $('div#id')

The first selector only returns the first occurence of the id, while the second will return a set of all elements with that id.

They should behave the same.

Change History

comment:1 Changed 2 years ago by pcvandam@…

jsFiddle-example:

 http://jsfiddle.net/y59Q7/

comment:2 Changed 2 years ago by rwaldron

  • Owner set to pcvandam@…
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to selector

Why would ever have >1 element with the same ID?

comment:3 Changed 2 years ago by pcvandam@…

  • Status changed from pending to new

That's not the point.

Of course it shouldn't happen, but with dynamically generated content it CAN happen. Fact is jQuery does not handle ID-selectors consistently.

comment:4 Changed 2 years ago by rwaldron

  • Status changed from new to pending

Actually, it is:  http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#the-id-attribute

If you write unexpected code, unexpected things happen.

Of course it shouldn't happen, but with dynamically generated content it CAN happen. Fact is jQuery does not handle ID-selectors consistently.

If this is an issue, the problem is not jQuery, it is the code that is dynamically generating elements that share IDs. The obvious approach is to write tests for your code that assert no duplicate IDs are created.

Last edited 2 years ago by rwaldron (previous) (diff)

comment:5 Changed 2 years ago by rwaldron

  • Status changed from pending to closed
  • Resolution set to wontfix

Just so you get a clearer picture, the "inconsistency" isn't jQuery's fault either:  http://jsfiddle.net/rwaldron/JZ8GX/

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.