- From: Cyril Auburtin <notifications@github.com>
- Date: Wed, 10 Feb 2016 13:06:08 -0800
- To: whatwg/dom <dom@noreply.github.com>
Received on Wednesday, 10 February 2016 21:06:40 UTC
It's probably really rare to need that ``` // returns the last element matching a selector from the reference element inside a container element // div#bar // div#foo1.foo // article // div.foo // span#qux // qux.furthest('.foo', bar) -> foo1 Node.prototype.furthest = function(selector, el = document){ // overloading dom prototypes can be bad :/ //if (el.matches(selector)) return el; let current = this.closest(selector); if (!current) return null; let _el = current.closest(el.tagName);// for avoiding having to call .closest until leaving el while( _el && _el !== el) { current = _el.parentNode; _el = current.closest(el.tagName) } return current; } ``` --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/163
Received on Wednesday, 10 February 2016 21:06:40 UTC