Re: [selectors-api] Summary of Feature Requests for v2

Lachlan Hunt wrote:
> Mike Wilson wrote:
>> My first priority would be "Matches Selector", and see to that
>> it fulfills the needs for event delegation.
>
> Is there any special functionality that would be needed to achieve 
> this?  If I understand correctly, event delegation just needs to be 
> able to check whether the event target element matches a given 
> selector.  So it would be something like:
>
> if (evt.target.matchesSelector(".foo>input.bar")) {
>    ...
> }
>

In case it isn't obvious, we may want to check every element in the 
event path. i.e. all ancestors of  evt.target.

If matchesSelector could be called with a context element then it would 
become a more powerful version of compareDocumentPosition(). It is also 
more limited because you can't do preceding-siblings.

Examples
I'll use the :scope pseudo-class, although :context would be a better name.

elt.matchesSelector(":scope *", context); // descendant
elt.matchesSelector(":scope > * *", context); // descendant but not child
elt.matchesSelector(":scope ~ *", context); // following-sibling
elt.matchesSelector(":scope ~ * > *", context); // nephew (child of a 
following-sibling)

I would probably use it if it was there, but wouldn't complain if it 
wasn't.

Received on Thursday, 24 September 2009 23:46:55 UTC