On 2011-10-18 18:42, Alex Russell wrote:
   HTMLDocument.prototype.find =
   HTMLElement.prototype.find = function(rootedSelector) {
      return this.querySelector(":scope " + rootedSelector);
    }

    HTMLDocument.prototype.findAll =
    HTMLElement.prototype.findAll = function(rootedSelector) {
      return this.querySelectorAll(":scope " + rootedSelector);
    }

What exactly does it mean to have a "rootedSelector" applied to the Document object? As I understand it, the scoping problem explained only seems to apply to running the query on elements, whereas the existing document.qsa already behaves as expected by authors. It doesn't seem to make sense to try and prepend :scope to selectors in that case.

e.g. document.find("html") shouldn't be equivalent to document.querySelector(":scope html");

So, either we introduce the new method only for elements, or we use a similarly named method on document for a similar, but slightly different purpose.

A previous use case discussed on this list is the ability to take a collection of elements, and execute the same selector on all all of them, as if iterating the list, collecting the results and returning a single merged collection.

The current API handles this use case with document.querySelectorAll, explicitly specifying :scope and passing a collection of refNodes.

e.g.
var list = ...; // Elements (Array, NodeList or indexed object)

// Find the sibling p elements of all elements in the list
document.querySelectorAll(":scope+p", list);

Thus, if we do introduce the proposed method, should it behave similarly, but with the implied rather than explicit :scope?

e.g.
document.findAll("+p", list);

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

Reply via email to