Created
May 3, 2020 07:28
-
-
Save sumitpore/2c740e6e34db4d2231361a965618acb5 to your computer and use it in GitHub Desktop.
jQuery closest's in Pure JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment