- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Mon, 9 Jan 2012 09:07:13 -0800
- 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).
[snip]
This is already supported in the Selectors API 2 draft:
<http://dev.w3.org/2006/webapi/selectors-api2/>
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')
~TJ
Received on Monday, 9 January 2012 17:08:10 UTC