Bug Tracker

Opened 14 years ago

Closed 14 years ago

Last modified 11 years ago

#4134 closed bug (invalid)

Selectors with multiple identical id is not works

Reported by: shagren Owned by:
Priority: major Milestone: 1.3.2
Component: unfiled Version: 1.3.1
Keywords: Cc:
Blocked by: Blocking:


Please look for next code

    <div id="t">
        <span id="t">
                some content
    <a href="#" onclick="javascript: alert($('div#t div#t').length); return false;">Click me</a>

I see empty result when click. With 1.2.6 - works good. With 1.3.1 and nightly build(r6170) works bad. When id is not identical works good.

Change History (4)

comment:1 Changed 14 years ago by Markus.Staab

its no valid html to have several elements with an equal id.. id hast to be unique

comment:2 Changed 14 years ago by dmethvin

Resolution: invalid
Status: newclosed

Right, ID attributes need to be unique. If they are not the browser can do something unpredictable.

comment:3 Changed 14 years ago by shagren

Resolution: invalid
Status: closedreopened

Yes, but it is works in 1.2.x. Then it can break old code. Then need return old behavior or document changes somewhere.

comment:4 Changed 14 years ago by dmethvin

Resolution: invalid
Status: reopenedclosed

Sorry, but jQuery can't guarantee consistent behavior across browsers when the document is invalid, and duplicate id attributes are such a case.

Your test case returns 0 in both 1.2.6 and 1.3.1, which seems correct even if duplicate id attributes were allowed. There is no div#t in the document that has a descendent div#t!

If you feel this merits further discussion, please do not reopen the ticket; take it to the jQuery Dev group.

Note: See TracTickets for help on using tickets.