Bug Tracker

Opened 9 years ago

Closed 9 years ago

#7182 closed bug

Combination Has Attribute Selector [name] + :first does not work

Reported by: raber@… Owned by: raber@…
Priority: undecided Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Description

HTML

<input autofocus type="text"/>

JS

$('input[autofocus]:first')

The combination of the three selectors does not find anything, combinations of input with either [autofocus] or :first work just fine, but obviously don't return the desired result.

Tested in FF 3.6.10 on WinXP and Win7

Change History (5)

comment:1 Changed 9 years ago by snover

Owner: set to raber@…
Status: newpending

Please provide a working testcase.

comment:2 Changed 9 years ago by jitter

Testcases:

http://jsfiddle.net/65GCU/ with jQuery 1.4.2

http://jsbin.com/ojaki with jQuery 1.4.3rc2

Bug confirmed (all on Windows XP) for jQuery 1.4.2 and 1.4.3rc2 in these browsers:

  • FF 2.0.0.20
  • FF 3.0.19
  • FF 3.5.11
  • FF 3.6.10
  • IE 6
  • Safari 3.1.2
  • Safari 3.2.3

Further info for FF 3.6.10:
$('input[autofocus]') works because the qSA handles this.
While $('input[autofocus]:first') fails because the qSA can't handle the :first and then Sizzles takes over.
For FF 3.6.10 the relevant Lines IMHO are Line 3277-3279, Line 3293 and Line 2856 in jquery-1.4.2.js.

As elem[ "autofocus" ] is undefined in FF 3.6.10 Sizzle ends up on Line 3293 and returns "" (the empty string which is the result of the getAttribute call) which in Line 2856 evaluates to false causing the elements to be considered as not matching the query.

Hope I got the debugging right. What I'm not sure of is if this is a browser bug or a jQuery (actually Sizzle) bug and if the latter is the case if Sizzle should handle this differently

Tested in:
FF 2.0.0.20, 3.0.19, 3.5.11, 3.6.10, 4.0b4;
Opera 9.64, 10.10, 10.54, 10.62;
Chrome 6.0.472.14;
IE 6;
Safari 3.1.2 (525.21), 3.2.3 (525.29), 4.0.4 (531.22.7), 5.0.1 (7533.17.8);


On a side note:

Additionally even only using $('input[autofocus]') fails in FF 2.0.0.20, 3.0.19 and IE 6

Last edited 9 years ago by jitter (previous) (diff)

comment:3 Changed 9 years ago by addyosmani

Further testing:

This is working fine in Safari 5.02 and the latest Chrome but I can't seem to get it working in the browsers listed above. (FF 3.6.10 does allow you to access input[autofocus] but isn't returning anything with :first).

There also appears to be quite a lot of reference available to autofocus compatibility in WebKit browsers but not so in anything outside of that, which leads me to believe that perhaps this is something which hasn't been fully (or correctly) implemented as a native feature in these other browsers.

Leaving open in case anyone else has further insights into this.

comment:4 Changed 9 years ago by jitter

This has nothing to do with autofocus in particular. I made similar tests with the attributes disabled and readonly instead of autofoucs (with the same browsers as posted above).

live test: disabled and :first
live test: readonly + :first

The bug doesn't exists for the disabled attribute in any browser I tested.

But for the readonly attribute the $("input[readonly]:first") call fails in all browsers tested (except IE6).

This leads me to believe that this is Sizzle issue where the evaluation fails if elem[ name ] (the DOM attribute) on Line 3277 jQuery-1.4.2.js returns undefined although the HTML attribute is set and elem.getAttribute( name ) returns the empty string (correctly) as no value for the attribute is specified.

I think this needs further investigation

Last edited 9 years ago by jitter (previous) (diff)

comment:5 Changed 9 years ago by trac-o-bot

Status: pendingclosed

Automatically closed due to 14 days of inactivity.

Note: See TracTickets for help on using tickets.