W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: querySelectorAll() -- selecting _immediate_ children of element

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 9 Jan 2012 09:07:13 -0800
Message-ID: <CAAWBYDA=8aV41eSW9VtK4QH7m0wjsgSedckk301Wm2Rt5ph13w@mail.gmail.com>
To: "Marat Tanalin | tanalin.com" <mtanalin@yandex.ru>
Cc: public-script-coord@w3.org
On Mon, Jan 9, 2012 at 6:17 AM, Marat Tanalin | tanalin.com
<mtanalin@yandex.ru> wrote:
> querySelector() and querySelectorAll() methods are exciting features, but they do not allow select _immediate_ children of reference element.
> To address this lack, we could use following syntax:
>    var divs = refElement.querySelectorAll('> DIV');
> Here 'divs' variable contains list of DIV elements that are immediate children (not just descendant elements) of reference element (refElement).

This is already supported in the Selectors API 2 draft:

Using the qS and qSA functions, you can pass a reference node as the
second argument, and select it with the :scope pseudoclass, like so:

document.querySelectorAll(':scope > div', refElement)

Using the find and findAll functions, you can just start a selector
with a combinator, like in your example:

refElement.findAll('> div')

Received on Monday, 9 January 2012 17:08:10 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:05 UTC