This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
The method either takes a function or a selector. While walking up the parent chain from the node on which the method was invoked, If the function returns true or the selector matches for the current node, it is returned, or null otherwise. Suggestion from Ojan.
Lachy, this might be something you're working on?
Okay, so basically this is the method that is desired: Element.prototype.ancestor = function(selector) { var node = this while((node = node.parent) && node.nodeType == Node.ELEMENT_NODE) if(node.matches(selector)) return node return null } Correct?
Anne, I think a method that returns the element itself or an ancestor (what the specification calls an _inclusive ancestor_) would be more useful. This is typically what you want when doing event delegation. The method name inclusiveAncestor() is not optimal though, so it would need some thinking.
jQuery and Dojo calls this closest(): http://api.jquery.com/closest/> and http://dojotoolkit.org/reference-guide/1.9/dojo/NodeList-traverse.html#closest Tab also suggested closest() a while ago: http://lists.w3.org/Archives/Public/www-style/2014Jan/0051.html It's not a verb, but neither is before() and after() for example.
https://github.com/whatwg/dom/commit/fd69cc7ed9251d12b1185b24e6f89d3f0481f39d Thanks David, hope you're enjoying your time off :-)