Bug Tracker

Opened 11 years ago

Closed 11 years ago

#10606 closed bug (wontfix)

#ID-selector inconsistent

Reported by: [email protected] Owned by: [email protected]
Priority: low Milestone: None
Component: selector Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:


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 (5)

comment:2 Changed 11 years ago by Rick Waldron

Component: unfiledselector
Owner: set to [email protected]
Priority: undecidedlow
Status: newpending

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

comment:3 Changed 11 years ago by [email protected]

Status: pendingnew

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 11 years ago by Rick Waldron

Status: newpending

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.

Version 0, edited 11 years ago by Rick Waldron (next)

comment:5 Changed 11 years ago by Rick Waldron

Resolution: wontfix
Status: pendingclosed

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

Note: See TracTickets for help on using tickets.