Bug Tracker

Ticket #11552 (closed feature: duplicate)

Opened 3 years ago

Last modified 2 years ago

Add support for :nth-of-type()

Reported by: wenz Owned by:
Priority: low Milestone: 1.next
Component: selector Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

The :nth-of-type CSS selector has been removed in jQuery 1.0. Given that recent browsers do support querySelector() and thus also support :nth-of-type(), I believe it would be a good idea to add :nth-of-type for legacy browsers. For instance, the example at  http://jsfiddle.net/Kr5yN/3/ works in all current browsers and IE9+, but fails in IE6-8.

Change History

comment:1 Changed 3 years ago by sindresorhus

  • Priority changed from undecided to low
  • Component changed from unfiled to selector

Nothing has changed since it was removed. A fallback for legacy browsers is still needed, and it's still a pretty obscure selector, and not worth the extra bloat. In most cases nth-child can be used instead.

If you really need it with jQuery, you can use this plugin:  https://github.com/keithclark/JQuery-Extended-Selectors or this:  http://css-tricks.com/snippets/jquery/add-nth-of-type-to-jquery/

Reasoning:  http://ejohn.org/blog/selectors-that-people-actually-use/

comment:2 Changed 3 years ago by dmethvin

Seems like a rare selector need to me. If you're in a situation where all the platforms you support provide querySelectorAll you can use it.

Since this is really a Sizzle issue, I'll leave it open for timmywil's call.

comment:3 Changed 3 years ago by timmywil

  • Status changed from new to open
  • Milestone changed from None to 1.next

I'm ok with adding it, but I think we should do some voting. There wouldn't be much extra bloat since we can reuse :nth-child's argument parsing, which has the same syntax.

comment:4 Changed 3 years ago by dmethvin

I'm okay with it if it's only a few bytes, since it's a cross-browser issue.

comment:5 Changed 2 years ago by timmywil

  • Status changed from open to closed
  • Resolution set to duplicate

This issue has been ported to a more widespread sizzle issue:  https://github.com/jquery/sizzle/issues/44

Note: See TracTickets for help on using tickets.