Skip to main content

Bug Tracker

Side navigation

#11413 closed bug (invalid)

Opened February 28, 2012 06:29PM UTC

Closed February 28, 2012 08:45PM UTC

jQuery Attribute Selector Bug

Reported by: Mike Murray <> 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

with a literal value of
, which is the
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
text field but also matches the
anchor link as well).

It appears what happens is that when the

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

text field and the
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

selector is appended to the attribute selector of
, it switches to behaving like the
attribute selector instead.

Attachments (0)
Change History (1)

Changed February 28, 2012 08:45PM UTC by sindresorhus comment:1

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: