W3C home > Mailing lists > Public > www-style@w3.org > January 2014

Re: [selectors4] Upwards Ancestor Traversal API

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Mon, 6 Jan 2014 10:37:49 -0800
Message-ID: <CABZUbM1DN4Cod6E_bqhB39mKDpWnoL=DQZG1mc_o4KUeSVkZag@mail.gmail.com>
To: Henrik Andersson <henke@henke37.cjb.net>
Cc: www-style@w3.org
On 1/6/14, Henrik Andersson <henke@henke37.cjb.net> wrote:
> Garrett Smith skriver:
>> For event bubbling, it is very useful to traverse up the DOM tree to
>> find an ancestor. For example:
>>  findAncestorWithClass(el, className,  /*opt*/ container);
>>  findAncestorWithAttribute(el, attName, /*opt*/ value);
>>  jqueryObj.closest(selectorText, /*opt*/ context)
>> It would be useful to have an API that traverses up the DOM tree and
>> tests each Element against a selector and returns either an Element or
>> null.
>> Proposal:
>>  querySelectorAncestor(startNode, selectorText[, optional Node
>> container);
>> If container is not specified, container is the root node.
>> Let currentParent be startNode.parentNode. While currentParent is not
>> container, if currentParent matches selectorText, it is returned.
> Might as well let people provide a callback that checks if each node is
> desired or not.
Even more useful if there had been a Selector defined as a callable
object, so that it would be interchangeable with function objects.
Received on Monday, 6 January 2014 18:38:17 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:38 UTC