- From: Sean Hogan <shogun70@westnet.com.au>
- Date: Tue, 12 Jan 2010 00:25:11 +1100
- To: Boris Zbarsky <bzbarsky@MIT.EDU>
- CC: Lachlan Hunt <lachlan.hunt@lachy.id.au>, public-webapps <public-webapps@w3.org>
On 11/01/10 6:40 PM, Boris Zbarsky wrote: > On 1/11/10 1:24 AM, Sean Hogan wrote: >> That's correct. jQuery's $(element).find("div") is the equivalent of >> SelectorsAPI2's element.querySelectorAll(":scope div") or > > So in fact jquery can simply implement Element.find in terms of > querySelectorAll by just prepending ":scope " to the selector string, > right? Note that this happens to work even for the "> div" case (by > converting the selector to ":scope > div", which is what jquery means). > > So the "> div" thing doesn't seem to require preparsing (modulo commas > in the selector; was that the key point?). Of course the jquery > selectors that aren't in CSS do (or possibly post-parsing depending on > how it's implemented). > If we could assume that commas only ever delimit selectors in a selector-string, and if jQuery didn't support selectors not implemented by the browser then something like the following conversion would be sufficient for all jQuery queries: function preprocess(str) { return ":scope " + str.split(",").join(", :scope "); } Hence no value is added by queryScopedSelector*(). If we can't assume those things then jQuery will still need its current selector parser. Hence no value is added by queryScopedSelector*(). >> My point is that jQuery's $(element).find("> div") isn't supported >> (without pre-processing by the JS lib) by >> element.queryScopedSelectorAll(). > > ... > >> element.queryScopedSelectorAll(":scope > div") generally becomes >> element.parentNode.querySelectorAll(":scope > div", element) which is >> the same as >> element.querySelectorAll(":scope > div", element) or even >> element.querySelectorAll(":scope > div") > > That's what I'm confused about. Does implementing element.find("> > div") as element.queryScopedSelectorAll(":scope > div") not do what > the current jquery code does? If not, how do they differ? > They will select the same list of elements. As will element.querySelectorAll(":scope > div") > I'm still confused about queryScopedSelectorAll, though. It sounds > from your example like queryScopedSelectorAll just prepends ":scope " > to the whole query string and then calls querySelectorAll on the > parentNode of the scope node, with the scope node passed in as the > optional argument. So: > > element.queryScopedSelectorAll(myStr) > > is the same as: > > element.parentNode.querySelectorAll(":scope " + myStr, element); > > is that correct? > For some selector-strings yes. More specifically, the parsing rules for scoped selectors are at: http://dev.w3.org/2006/webapi/selectors-api2/#parse-a-scoped-selector Scoped selectors must still be valid selectors, so "> div", "+ div", "~ div" will all throw exceptions. They must be explicitly written as ":scope > div", etc in the call to element.queryScopedSelectorAll(). Thus the queryScopedSelectorAll call won't prepend them with ":scope ".
Received on Monday, 11 January 2010 13:25:58 UTC