Re: Behavior of matches() and closest() with :scope()

"Tab Atkins Jr." <[email protected]>
Newsgroups gmane.comp.web.dom.general,gmane.comp.web.css.general
Message-ID <CAAWBYDDd-iGPtFYroU=X1+6r_ZTj4r_e-XSDoULWbsJ-t8Ce_Q@mail.gmail.com>
On Tue, Sep 2, 2014 at 9:24 AM, Boris Zbarsky <[email protected]> wrote:
> On 9/2/14, 12:20 PM, Anne van Kesteren wrote:
>>
>> On Tue, Sep 2, 2014 at 6:11 PM, Tab Atkins Jr. <[email protected]>
>> wrote:
>>>
>>> #1 is what I was intending, but looking at closest() now, I don't see
>>> a restriction to just compound selectors.  If complex selectors are
>>> allowed, then I guess it makes more sense to match matches() and have
>>> :scope refer to the element you're matching against.  It makes it
>>> harder to do some things, but they're probably rare and can be handled
>>> explicitly anyway.
>>
>>
>> Hmm yes, so 2) then? :-)
>
>
> I think I personally would prefer 1); it's not clear to me why complex
> selectors make a difference here.

For the same reason that :scope matches the element in .matches().
Anything you might want to pass to .matches(), you might want to pass
to .closest().

#1 would allow you to write a .closest() selector which, paired with
:has(), can explicitly reference the starting element, but you can
reproduce that if necessary by adding a uniquifier to the starting
element and matching on that.

~TJ
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.