Bug Tracker

Opened 11 years ago

Closed 11 years ago

#11413 closed bug (invalid)

jQuery Attribute Selector Bug

Reported by: Mike Murray <[email protected]…> Owned by:
Priority: low Milestone: None
Component: selector Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:



At the above jsFiddle example, we have extremely simple markup:

<input tabindex="0" name="Username" />
<input tabindex="1" name="Password" />
<input type="hidden" name="Hidden" value="value" />
<input tabindex="2" type="submit" value="Submit" />
<a href="#" id="ForgotPassword">Forgot Password?</a>​

When I do the following jQuery selectors in the JavaScript console of Chrome Dev Tools or Firebug...


...I get confusing results. The first selector does as I intended (i.e., select the single html element on the page that has an attribute of tabindex with a literal value of 0, which is the Username input text field). I would then expect the second selector to produce the same result, as it has the same selector but with one extra restriction that the element be visible. However, I actually get more results than the first, despite the more restrictive selector (i.e., it matches Username text field but also matches the ForgotPassword anchor link as well).

It appears what happens is that when the :visible selector is added, the attribute selector is not doing a literal match anymore. When I do the same attribute selector, but without quotes...


...I now get all elements which effectively have a tab index of zero by default, not just the one that literally has the attribute in its markup (i.e., now we match the Username text field and the ForgotPassword link, and additionally the hidden input field in the case of the selector without the visibility check).

What I'm gathering is that when the :visible selector is appended to the attribute selector of [tabindex="0"], it switches to behaving like the [tabindex=0] attribute selector instead.

Change History (1)

comment:1 Changed 11 years ago by sindresorhus

Component: unfiledselector
Priority: undecidedlow
Resolution: invalid
Status: newclosed

This is not a jQuery bug.

tabIndex="0" means:

In tab order relative to element's position in document.


You should begin your tabIndex with 1: http://jsfiddle.net/mofle/qD5Se/1/

Note: See TracTickets for help on using tickets.