inexorabletash/polyfill

Add support for proposed Element.closest

tmorehouse opened this issue · 4 comments

The Element.closest() method provides a way to search up the dom tree for a node matching a CSS selector

from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest

if (window.Element && !Element.prototype.closest) {
    Element.prototype.closest = 
    function(s) {
        var matches = (this.document || this.ownerDocument).querySelectorAll(s),
            i,
            el = this;
        do {
            i = matches.length;
            while (--i >= 0 && matches.item(i) !== el) {};
        } while ((i < 0) && (el = el.parentElement)); 
        return el;
    };
}

I would like to see this added as well!

@inexorabletash Can you publish a new version now that my PR is merged? :)

Done, thanks for the prompt!

Resolved by b46b5c7