Bug Tracker

Ticket #6838 (closed bug: wontfix)

Opened 4 years ago

Last modified 2 years ago

: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:
Blocking: Blocked by:

Description (last modified by rwaldron) (diff)

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

test-6838.html Download (696 bytes) - added by dmethvin 4 years ago.
Test case

Change History

comment:1 Changed 4 years ago by dmethvin

  • Keywords first added; selectors removed
  • Component changed from core to selector

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

Test case

comment:2 Changed 4 years ago by snover

#5700 is a duplicate of this ticket.

comment:3 Changed 4 years ago by snover

  • Priority set to blocker
  • Status changed from new to open
  • Version changed from 1.4.2 to 1.4.3
  • Milestone changed from 1.4.3 to 1.4.4

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

  • Milestone changed from 1.4.4 to 1.4.5

Retargeting due to severity of regressions in 1.4.3.

comment:7 Changed 4 years ago by snover

  • Milestone changed from 1.4.5 to 1.4.4

Retargeting for 1.4.4 as per John’s request.

comment:8 Changed 4 years ago by john

  • Owner set to john
  • Status changed from open to assigned

comment:9 Changed 4 years ago by snover

  • Milestone changed from 1.4.4 to 1.4.5

Retargeting to next minor release.

comment:10 Changed 4 years ago by john

  • Milestone changed from 1.4.5 to 1.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 3 years ago by john

  • Milestone changed from 1.6 to 1.next

comment:12 Changed 3 years ago by john

  • Keywords first,1.7-discuss added; first removed

Nominating ticket for 1.7 discussion.

comment:13 Changed 3 years ago by rwaldron

  • Description modified (diff)

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

comment:14 Changed 3 years ago by jaubourg

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

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

  • Description modified (diff)

+1, sounds like a bug

comment:17 Changed 3 years ago by dmethvin

  • Description modified (diff)

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

comment:18 Changed 3 years ago by john

  • Description modified (diff)

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

comment:19 Changed 3 years ago by scott.gonzalez

+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 3 years ago by addyosmani

+1

comment:21 Changed 3 years ago by jzaefferer

+1

comment:22 Changed 3 years ago by rwaldron

  • Status changed from assigned to closed
  • Description modified (diff)
  • Priority changed from blocker to low
  • Milestone changed from 1.next to 1.7
  • Keywords first,1.7-discuss removed
  • Resolution set to wontfix
Note: See TracTickets for help on using tickets.