Skip to main content

Bug Tracker

Side navigation

#11040 closed bug (invalid)

Opened December 16, 2011 08:05AM UTC

Closed December 16, 2011 04:33PM UTC

Last modified October 29, 2012 06:49PM UTC

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

Reported by: epassi@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
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.

Attachments (0)
Change History (3)

Changed December 16, 2011 04:33PM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

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.

Changed October 29, 2012 04:18PM UTC by info@connexo.de comment:2

Replying to [comment:1 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.

Changed October 29, 2012 06:49PM UTC by dmethvin comment:3

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