Skip to main content

Bug Tracker

Side navigation

#6838 closed bug (wontfix)

Opened July 28, 2010 07:48AM UTC

Closed June 06, 2011 06:41PM UTC

Last modified March 13, 2012 09:38PM UTC

:first selector behaves differently between IE8 and FF 3.6.8

Reported by: grimace Owned by: john
Priority: low Milestone: 1.7
Component: selector Version: 1.4.3
Keywords: Cc:
Blocked by: Blocking:
Description

I have the following html snippet:

<h1>Header</h1>
<div class="Item">Item 1</div>
<div class="Item">Item 2</div>

If I release the following selectors on it:

$(".Item:not(:first)")
$(".Item:not(.Item:first)")

I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.

Attachments (1)
  • test-6838.html (0.7 KB) - added by dmethvin August 04, 2010 02:21AM UTC.

    Test case

Change History (22)

Changed August 04, 2010 02:21AM UTC by dmethvin comment:1

component: coreselector
keywords: selectorsfirst

It seems like the correct answer would be 2 for the first case and 1 for the second. If everyone agrees, then IE8 gets it right in my test case and Firefox gets the first case wrong.

The :first element for Firefox 3.6 is the HTML element; in IE it's the !DOCTYPE comment element. In general it seems like a bad idea to use an unqualified :first selector but the Firefox behavior seems pretty strange.

Changed October 18, 2010 11:49PM UTC by snover comment:2

#5700 is a duplicate of this ticket.

Changed October 18, 2010 11:50PM UTC by snover comment:3

milestone: 1.4.31.4.4
priority: → blocker
status: newopen
version: 1.4.21.4.3

Changed October 19, 2010 08:06AM UTC by tomgrohl comment:4

I've found that this works in Firefox 3.6.10, but not in IE8

( but works fine for both when :last is used ):

alert( $(".Item:not(:first)").length );
alert( $(".Item:not(.Item:first)").length );

But this works in both ( returns 1 for length)

alert( $(".Item").not(":first").length );
alert( $(".Item").not(".Item:first").length );

Changed October 20, 2010 09:49AM UTC by tomgrohl comment:5

You gave me an idea when you said that $(":first") returns Html node for Firefox and Doctype comment for IE 8.

That would mean than the root (:root) would be different in each browser (well IE 8 anyways)

So I tried the following, adding body (html works too) in to the mix to give it a different root:

$("body .Item:not(:first)") //length of 1 for both
$("body .Item:not(.Item:first)") //length of 1 for both

And this works.

It seems if a different root is prepended to it, and not letting Sizzle set the root, then it works.

You can find a test of it here

Hope this is of some help.

Changed October 21, 2010 10:59PM UTC by snover comment:6

milestone: 1.4.41.4.5

Retargeting due to severity of regressions in 1.4.3.

Changed October 22, 2010 05:53AM UTC by snover comment:7

milestone: 1.4.51.4.4

Retargeting for 1.4.4 as per John’s request.

Changed October 23, 2010 07:18PM UTC by john comment:8

owner: → john
status: openassigned

Changed October 28, 2010 02:09AM UTC by snover comment:9

milestone: 1.4.41.4.5

Retargeting to next minor release.

Changed January 17, 2011 05:12PM UTC by john comment:10

milestone: 1.4.51.6

I want to save this for 1.6 when the selector rewrite happens - a lot of this code will be changing and there's not much point in fiddling with it now.

Changed April 17, 2011 08:38PM UTC by john comment:11

milestone: 1.61.next

Changed May 22, 2011 07:27PM UTC by john comment:12

keywords: firstfirst,1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 10:07PM UTC by rwaldron comment:13

description: I have the following html snippet: \ \ {{{ \ <h1>Header</h1> \ <div class="Item">Item 1</div> \ <div class="Item">Item 2</div> \ }}} \ \ If I release the following selectors on it: \ {{{ \ $(".Item:not(:first)") \ $(".Item:not(.Item:first)") \ }}} \ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.I have the following html snippet:\ \ {{{\ <h1>Header</h1>\ <div class="Item">Item 1</div>\ <div class="Item">Item 2</div>\ }}}\ \ If I release the following selectors on it:\ {{{\ $(".Item:not(:first)")\ $(".Item:not(.Item:first)")\ }}}\ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.

+0, If it's a bug, it should be fixed, but this seems awkward

Changed May 23, 2011 12:07AM UTC by jaubourg comment:14

+0, Smells fishy... need a fiddle to see if document structure is the problem here.

Changed May 23, 2011 02:06AM UTC by ajpiano comment:15

description: I have the following html snippet:\ \ {{{\ <h1>Header</h1>\ <div class="Item">Item 1</div>\ <div class="Item">Item 2</div>\ }}}\ \ If I release the following selectors on it:\ {{{\ $(".Item:not(:first)")\ $(".Item:not(.Item:first)")\ }}}\ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.I have the following html snippet: \ \ {{{ \ <h1>Header</h1> \ <div class="Item">Item 1</div> \ <div class="Item">Item 2</div> \ }}} \ \ If I release the following selectors on it: \ {{{ \ $(".Item:not(:first)") \ $(".Item:not(.Item:first)") \ }}} \ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.

+0, I guess that if it's a bug, then we should fix it, but also, there's a :gt selector for this...

Changed May 23, 2011 03:25AM UTC by timmywil comment:16

description: I have the following html snippet: \ \ {{{ \ <h1>Header</h1> \ <div class="Item">Item 1</div> \ <div class="Item">Item 2</div> \ }}} \ \ If I release the following selectors on it: \ {{{ \ $(".Item:not(:first)") \ $(".Item:not(.Item:first)") \ }}} \ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.I have the following html snippet:\ \ {{{\ <h1>Header</h1>\ <div class="Item">Item 1</div>\ <div class="Item">Item 2</div>\ }}}\ \ If I release the following selectors on it:\ {{{\ $(".Item:not(:first)")\ $(".Item:not(.Item:first)")\ }}}\ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.

+1, sounds like a bug

Changed May 23, 2011 09:48PM UTC by dmethvin comment:17

description: I have the following html snippet:\ \ {{{\ <h1>Header</h1>\ <div class="Item">Item 1</div>\ <div class="Item">Item 2</div>\ }}}\ \ If I release the following selectors on it:\ {{{\ $(".Item:not(:first)")\ $(".Item:not(.Item:first)")\ }}}\ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.I have the following html snippet: \ \ {{{ \ <h1>Header</h1> \ <div class="Item">Item 1</div> \ <div class="Item">Item 2</div> \ }}} \ \ If I release the following selectors on it: \ {{{ \ $(".Item:not(:first)") \ $(".Item:not(.Item:first)") \ }}} \ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.

-1, Let's push folks towards standards selectors and not muck around here.

Changed June 03, 2011 01:34PM UTC by john comment:18

description: I have the following html snippet: \ \ {{{ \ <h1>Header</h1> \ <div class="Item">Item 1</div> \ <div class="Item">Item 2</div> \ }}} \ \ If I release the following selectors on it: \ {{{ \ $(".Item:not(:first)") \ $(".Item:not(.Item:first)") \ }}} \ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.I have the following html snippet:\ \ {{{\ <h1>Header</h1>\ <div class="Item">Item 1</div>\ <div class="Item">Item 2</div>\ }}}\ \ If I release the following selectors on it:\ {{{\ $(".Item:not(:first)")\ $(".Item:not(.Item:first)")\ }}}\ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.

+0, Ugh... :first semantics inside :not(), just terrible.

Changed June 03, 2011 02:51PM UTC by scottgonzalez comment:19

+0, There's clearly a bug in there and I wonder if it exists with other selectors too. However, I'm guessing this is really tricky to fix and there's an existing, better way to do the same thing.

Changed June 04, 2011 10:17PM UTC by addyosmani comment:20

+1

Changed June 06, 2011 03:51PM UTC by jzaefferer comment:21

+1

Changed June 06, 2011 06:41PM UTC by rwaldron comment:22

description: I have the following html snippet:\ \ {{{\ <h1>Header</h1>\ <div class="Item">Item 1</div>\ <div class="Item">Item 2</div>\ }}}\ \ If I release the following selectors on it:\ {{{\ $(".Item:not(:first)")\ $(".Item:not(.Item:first)")\ }}}\ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.I have the following html snippet: \ \ {{{ \ <h1>Header</h1> \ <div class="Item">Item 1</div> \ <div class="Item">Item 2</div> \ }}} \ \ If I release the following selectors on it: \ {{{ \ $(".Item:not(:first)") \ $(".Item:not(.Item:first)") \ }}} \ \ I get Firefox to return 2 in both cases. IE8 will return 1 in the first case, and 2 in the second.
keywords: first,1.7-discuss
milestone: 1.next1.7
priority: blockerlow
resolution: → wontfix
status: assignedclosed