Skip to main content

Bug Tracker

Side navigation

#7182 closed bug ()

Opened October 13, 2010 08:07PM UTC

Closed November 11, 2010 11:09PM UTC

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

Reported by: raber@h2a.lu Owned by: raber@h2a.lu
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

Attachments (0)
Change History (5)

Changed October 13, 2010 09:20PM UTC by snover comment:1

owner: → raber@h2a.lu
status: newpending

Please provide a working testcase.

Changed October 13, 2010 11:59PM UTC by jitter comment:2

_comment0: Testcase: \ [http://jsfiddle.net/65GCU/ http://jsfiddle.net/65GCU/] \ \ Bug confirmed in (all on Windows XP): \ - 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 \ \ Tested in:[[BR]] \ FF 2.0.0.20, 3.0.19, 3.5.11, 3.6.10, 4.0b4;[[BR]] \ Opera 9.64, 10.10, 10.54, 10.62;[[BR]] \ Chrome 6.0.472.14;[[BR]] \ IE 6;[[BR]] \ Safari 3.1.2 (525.21), 3.2.3 (525.29), 4.0.4 (531.22.7), 5.0.1 (7533.17.8); \ 1287015401742498
_comment1: Testcase: \ [http://jsfiddle.net/65GCU/ http://jsfiddle.net/65GCU/ with jQuery 1.4.2] \ \ [http://jsbin.com/ojaki http://jsbin.com/ojaki with jQuery 1.4.3rc2] \ \ Bug confirmed in (all on Windows XP) for jQuery 1.4.2 and 1.4.3rc2: \ - 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 \ \ Additionally even only {{{$('input[autofocus]')}}} fails in FF 2.0.0.20, 3.0.19 and IE 6 \ \ I guess this actually is a Sizzle bug in combination with different browser behavior. e.g. FF 3.6.10 for {{{$('input[autofocus]:first')}}} the \ \ Tested in:[[BR]] \ FF 2.0.0.20, 3.0.19, 3.5.11, 3.6.10, 4.0b4;[[BR]] \ Opera 9.64, 10.10, 10.54, 10.62;[[BR]] \ Chrome 6.0.472.14;[[BR]] \ IE 6;[[BR]] \ Safari 3.1.2 (525.21), 3.2.3 (525.29), 4.0.4 (531.22.7), 5.0.1 (7533.17.8); \ 1287016118649676
_comment2: Testcases: \ \ [http://jsfiddle.net/65GCU/ http://jsfiddle.net/65GCU/ with jQuery 1.4.2] \ \ [http://jsbin.com/ojaki 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 \ \ Additionally even only using `$('input[autofocus]')` fails in FF 2.0.0.20, 3.0.19 and IE 6 \ \ I guess this actually is a Sizzle bug caused by different browser behavior and different execution paths. e.g. in FF 3.6.10 and Opera 10.52 `$('input[autofocus]')` works because the qSA works. While for `$('input[autofocus]:first')` qSA fails and then the Sizzle evaluation delivers different results in different browsers (which I assume could have to do with different return values for get `getAttribute` function) \ \ Tested in:[[BR]] \ FF 2.0.0.20, 3.0.19, 3.5.11, 3.6.10, 4.0b4;[[BR]] \ Opera 9.64, 10.10, 10.54, 10.62;[[BR]] \ Chrome 6.0.472.14;[[BR]] \ IE 6;[[BR]] \ Safari 3.1.2 (525.21), 3.2.3 (525.29), 4.0.4 (531.22.7), 5.0.1 (7533.17.8); \ 1287018935690530
_comment3: Testcases: \ \ [http://jsfiddle.net/65GCU/ http://jsfiddle.net/65GCU/ with jQuery 1.4.2] \ \ [http://jsbin.com/ojaki 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:[[BR]] \ `$('input[autofocus]')` works because the qSA handles this.[[BR]] \ While `$('input[autofocus]:first')` fails because the qSA can't handle the `:first` and then Sizzles takes over.[[BR]] \ 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. \ \ Tested in:[[BR]] \ FF 2.0.0.20, 3.0.19, 3.5.11, 3.6.10, 4.0b4;[[BR]] \ Opera 9.64, 10.10, 10.54, 10.62;[[BR]] \ Chrome 6.0.472.14;[[BR]] \ IE 6;[[BR]] \ 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 61287019129334374

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

Changed October 14, 2010 01:56AM UTC by addyosmani comment:3

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.

Changed October 14, 2010 10:24AM UTC by jitter comment:4

_comment0: 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). \ \ [http://jsfiddle.net/TFNGK/ live test: disabled and :first][[BR]] \ [http://jsfiddle.net/yKuvk/ 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 ]` on Line 3277 jQuery-1.4.2.js returns undefined although the DOM property is set but `elem.getAttribute( name )` returns the empty string as no value for the attribute is specified.1287052015759442
_comment1: 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). \ \ [http://jsfiddle.net/TFNGK/ live test: disabled and :first][[BR]] \ [http://jsfiddle.net/yKuvk/ 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 ]` on Line 3277 jQuery-1.4.2.js returns undefined although the DOM property is set but `elem.getAttribute( name )` returns the empty string as no value for the attribute is specified. \ \ I think this needs further investigation1287052118865494

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

Changed November 11, 2010 11:09PM UTC by trac-o-bot comment:5

status: pendingclosed

Automatically closed due to 14 days of inactivity.