Selectors in jQuery

I took a quick look at the list of selectors allowed by jQuery [1].
Mostly based on CSS 3 Selectors, it lacks a few of them while adding

:even           even elements, zero-indexed
:odd            odd elements, zero-indexed
:gt(n)          elements w/ index greater than n
:lt(n)          elements w/ index lower than n
:header         matches h1 to h6
:animated       elements that are currently animated
:contains(text) elements that contains the given text
:has(selector)  matches elements that contain at least one
                   element matching selector
:parent         matches elements that are parents
:hidden         elements that are hidden
:visible        elements that are visible
:file           match elements of the given type


A few observations:

- :even is redundant with :nth-child(even)
- :odd is redundant with :nth-child(odd)
- :gt(n) and :lt(n) are redundant with combinations of :not()
   and :nth-child() but are far easier to manage if n is high
- :header is just a html-centric convenience for a group of
- :animated is a weird thing since it relies on currenly executed
   scripts or CSS transitions, making a rule dependant on the computed
   value of a property
- :contains() was included in the old CSS 3 Selectors draft
- :has() is an old request of the community
- :parent is redundant with :not(:empty)
- :hidden and :visible can also be dependant on the computed
   value of CSS properties (BTW, display and/or visibility ?)
- the last additions are just shortcuts for lightly more complex

Of course, pseudo-elements are not here, but there's a :selected

John, is there a way we could make jQuery's list of accepted selectors
converge with CSS 3 Selectors ? Does the Selectors API help here ?


W3C CSS WG, Co-Chair

Received on Thursday, 9 October 2008 08:10:39 UTC