Re: Selectors in jQuery

John Resig wrote:
> There is also :first and :last - and no they are not equivalent to
> using nth-child. They are scoped to the entire matched selector - for
> example doing 'div:first' would find the first div on the page - not
> all divs that are the first child element.

The thing with these is that in the context jQuery uses them in they're
really simple to implement (heck, document.querySelectorAll("...")[0]
for "...:first").  But if they're used to attach style, then dynamic
updates become a pain: any dynamic change that might add or remove nodes
needs to be compared to the position of the thing that matched the
:first, for example.

There would have to be some really convincing use cases for styling
here, and I'm not sure I see any offhand.

>> :input,
> 
> This is equivalent to (textarea, input, select, button)

But not <isindex> or <object> (the latter can submit, in theory).

> And this is equivalent to ([type=button], button)

But not input[type=submit] or input[type=reset]?

> I should note that :selected, in our case, refers to a selected
> option in a <select> element.

option:checked should work, in UAs that support that, as you note below.

-Boris

Received on Thursday, 9 October 2008 17:06:22 UTC