Bug Tracker

Ticket #11040 (closed bug: invalid)

Opened 3 years ago

Last modified 2 years ago

first-of-type pseudoselector suddenly "unrecognized" in Internet Explorer 8

Reported by: epassi@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

I'm encountering this bug using:

  • IE8
  • WinXP
  • jQuery 1.7.1 and earlier versions

Doesn't reproduce in Safari, Firefox, Chrome on Mac or Windows. I don't have access to any other versions of IE.

=======

Background: IE8 doesn't recognize the CSS first-of-type pseudoselector, so I'm using jQuery to insert a custom class, like this:

$("h2:first-of-type").addClass("ie-first-heading");

This worked perfectly on Dec 12, 2011. But today (Dec 15) the page isn't rendering properly, and I notice this error in IE8:


Syntax error, unrecognized expression: first-of-type Line: 3 Char: 14659 Code: 0 URI:  http://code.jquery.com/jquery-1.7.1.min.js


Did something change in jQuery 1.7.1 over the past few days? My HTML is pointing directly to the jQuery URL; I don't use a local copy.

Please let me know if I can provide more info.

Change History

comment:1 follow-up: ↓ 2 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Well, :first-of-type isn't a selector that jQuery provides cross-browser support for, so you're depending on the native querySelectorAll to do its job. That means the code won't work on IE6 or IE7, don't know if that's an issue for your page.

Most likely what is happening is that your IE8 has dropped into Quirks mode due to either a missing/bad doctype or other document error (two body tags for example). When IE8 is in Quirks it no longer uses the native querySelectorAll, and you would get that message from Sizzle.

comment:2 in reply to: ↑ 1 Changed 2 years ago by info@…

Replying to dmethvin:

Well, :first-of-type isn't a selector that jQuery provides cross-browser support for, so you're depending on the native querySelectorAll to do its job. That means the code won't work on IE6 or IE7, don't know if that's an issue for your page.

Most likely what is happening is that your IE8 has dropped into Quirks mode due to either a missing/bad doctype or other document error (two body tags for example). When IE8 is in Quirks it no longer uses the native querySelectorAll, and you would get that message from Sizzle.

I have the same problem on Win7/IE8. The thing is: Many times you need the pseudo selector in a jQuery expression to add a class to the matched items, and thus, add "virtual" support for browsers not supporting :first-of-type. Adding the class in general is exactly what you want to avoid by using jQuery.

comment:3 Changed 2 years ago by dmethvin

This ticket isn't about adding a feature so there's no need to justify why you need it. There is already a ticket for Sizzle to add support for more CSS3 selectors:  https://github.com/jquery/sizzle/issues/44

Note: See TracTickets for help on using tickets.