Bug Tracker

Opened 10 years ago

Last modified 9 years ago

#6838 closed bug

:first selector behaves differently between IE8 and FF 3.6.8 — at Version 16

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

Description (last modified by timmywil)

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.

Change History (17)

comment:1 Changed 10 years ago by dmethvin

Component: coreselector
Keywords: first added; selectors removed

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 10 years ago by dmethvin

Attachment: test-6838.html added

Test case

comment:2 Changed 10 years ago by snover

#5700 is a duplicate of this ticket.

comment:3 Changed 10 years ago by snover

Milestone: 1.4.31.4.4
Priority: blocker
Status: newopen
Version: 1.4.21.4.3

comment:4 Changed 10 years ago by tomgrohl

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 );

comment:5 Changed 10 years ago by tomgrohl

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.

comment:6 Changed 10 years ago by snover

Milestone: 1.4.41.4.5

Retargeting due to severity of regressions in 1.4.3.

comment:7 Changed 10 years ago by snover

Milestone: 1.4.51.4.4

Retargeting for 1.4.4 as per John’s request.

comment:8 Changed 10 years ago by john

Owner: set to john
Status: openassigned

comment:9 Changed 10 years ago by snover

Milestone: 1.4.41.4.5

Retargeting to next minor release.

comment:10 Changed 10 years ago by john

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.

comment:11 Changed 10 years ago by john

Milestone: 1.61.next

comment:12 Changed 10 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:13 Changed 10 years ago by Rick Waldron

Description: modified (diff)

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

comment:14 Changed 10 years ago by jaubourg

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

comment:15 Changed 10 years ago by ajpiano

Description: modified (diff)

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

comment:16 Changed 10 years ago by timmywil

Description: modified (diff)

+1, sounds like a bug

Note: See TracTickets for help on using tickets.