A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

[Proposal] :nth-of-selector()

nicolasjengler
2016-11-09

Is :nth-of-selector() something factuable enough to create a draft proposal? The main idea would be to match the nth child with a certain selector, whether it is a class selector, an attribute selector, etcetera.

The two main reasons why I believe this pseudo-class can be useful are the following:

  1. There currently isn’t a way to target nth elements by their class or attribute (and I keep bringing this up because these would be one of the most used cases). :nth-of-type() only allows to target elements by their type, which can be difficult to deal with if I have multiple elements of the same type but want to style them differently. Accessing them depending on a certain particularity (e.g.: two distinct classes) could be a great improvement to structural pseudo-classes logic.
  2. Right now, using :nth-of-child() is a matter of major confusion for some folks, as some believe that pairing a certain selector with :nth-of-child() would apply the following set of defined properties only to the children that match said selector.
tabatkins
2016-11-09

Already in the spec, as :nth-child(<an+b> of <sel>).