Bug Tracker

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#6838 closed bug (wontfix)

: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 (last modified by Rick Waldron)

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 (696 bytes) - added by dmethvin 7 years ago.
Test case

Download all attachments as: .zip

Change History (23)

comment:1 Changed 7 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 7 years ago by dmethvin

Attachment: test-6838.html added

Test case

comment:2 Changed 7 years ago by snover

#5700 is a duplicate of this ticket.

comment:3 Changed 7 years ago by snover

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

comment:4 Changed 7 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 7 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 7 years ago by snover

Milestone: 1.4.41.4.5

Retargeting due to severity of regressions in 1.4.3.

comment:7 Changed 7 years ago by snover

Milestone: 1.4.51.4.4

Retargeting for 1.4.4 as per John’s request.

comment:8 Changed 7 years ago by john

Owner: set to john
Status: openassigned

comment:9 Changed 7 years ago by snover

Milestone: 1.4.41.4.5

Retargeting to next minor release.

comment:10 Changed 7 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 6 years ago by john

Milestone: 1.61.next

comment:12 Changed 6 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:13 Changed 6 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 6 years ago by jaubourg

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

comment:15 Changed 6 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 6 years ago by timmywil

Description: modified (diff)

+1, sounds like a bug

comment:17 Changed 6 years ago by dmethvin

Description: modified (diff)

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

comment:18 Changed 6 years ago by john

Description: modified (diff)

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

comment:19 Changed 6 years ago by scottgonzalez

+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.

comment:20 Changed 6 years ago by addyosmani

+1

comment:21 Changed 6 years ago by jzaefferer

+1

comment:22 Changed 6 years ago by Rick Waldron

Description: modified (diff)
Keywords: first 1.7-discuss removed
Milestone: 1.next1.7
Priority: blockerlow
Resolution: wontfix
Status: assignedclosed
Note: See TracTickets for help on using tickets.