Skip to main content

Bug Tracker

Side navigation

#10606 closed bug (wontfix)

Opened October 28, 2011 01:37PM UTC

Closed October 28, 2011 02:33PM UTC

#ID-selector inconsistent

Reported by: pcvandam@gmail.com Owned by: pcvandam@gmail.com
Priority: low Milestone: None
Component: selector Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:
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.

Attachments (0)
Change History (5)

Changed October 28, 2011 01:40PM UTC by pcvandam@gmail.com comment:1

jsFiddle-example:

http://jsfiddle.net/y59Q7/

Changed October 28, 2011 02:23PM UTC by rwaldron comment:2

component: unfiledselector
owner: → pcvandam@gmail.com
priority: undecidedlow
status: newpending

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

Changed October 28, 2011 02:26PM UTC by pcvandam@gmail.com comment:3

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.

Changed October 28, 2011 02:29PM UTC by rwaldron comment:4

_comment0: 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.1319812243631810
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.

>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.

Changed October 28, 2011 02:33PM UTC by rwaldron comment:5

resolution: → wontfix
status: pendingclosed

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