Re: getElementsBySelectoron all NodeLists

Ian Hickson wrote:
> On Fri, 23 Sep 2005, Sjoerd Visscher wrote:
>> These features would be nice for all methods that return NodeLists. As 
>> NodeLists are live, adding a contains method, and a modification event 
>> to the NodeList interface should cover all you need and much more.

The use cases for applying the selector apis to NodeLists aren't yet 
clear.  I have not added the feature to this version of the spec, but it 
could be something worth considering in the future.

I discussed this on IRC [1].  For future reference, here's the chat log.

<Hixie> Lachy: i have a request here from someone suggesting the
         query-by-selectors api should apply to all NodeList objects too
<Lachy> I'm not sure I could get it into this first version of the spec,
         but it might be an interesting extension for the next revision
<Lachy> especially since we're starting to get implementations already,
         I'd rather focus on getting interop with the current feature set
         before piling on more
<annevk> how does it work on NodeList?
<Lachy> I assume it would evaluate each node in the list, in the context
         of the document it's in
<Dashiva> So it's more like using the nodelist as a filter to the query
           result
<Lachy> e.g. var list = document.getElementsByTagName("p");
         var filteredList = list.querySelector("div>p");
<Lachy> so filteredList would contain all the p elements from list,
         which are children of div elements in the document
<Lachy> not sure of the use case though, since
         document.querySelector("div>p"); would do the same
<Hixie> yeah i dunno what the use case is exactly, though there are
         other places that return NodeLists
<Lachy> I suppose that would have been sent before the webapi wg was
         formed, and thus hadn't begun working on selectors api.
<Dashiva> By making querySelector work on nodelists, it would be
           possible to chain querySelector calls too...
<Lachy> so that's why you wouldn't have forwarded it then
<Hixie> Lachy: yeah it ended up in the worng bucket
<Lachy> Dashiva, what's the point in chaining queryselector calls?
<Lachy> just chain the selctors and make one call
<Dashiva> Lachy: If you want to select something based on ancestors or
           preceding siblings, CSS isn't very helpful
<Hixie> document.querySelector('a x').querySelector('b x') is equivalent
         to 'a b x, b a x' which can get much more complex
<Lachy> Dashiva, I assume you meant if you want to select ancestors or
         preceding siblings, rather than something based on those (since
         selectors already work the way you said it)
<Dashiva> Yeah, that
<Dashiva> And Hixie seems to have found an even better case :)
<Hixie> it's a bit like having :matches(... #)
<Lachy> oh, right
<Lachy> it's worth thinking about, but definitely need to evaluate the
         use cases and see how authors actually use these apis

[1] http://krijnhoetmer.nl/irc-logs/whatwg/20080415#l-831

-- 
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/

Received on Tuesday, 15 April 2008 21:09:35 UTC