Last active
December 10, 2019 03:52
-
-
Save jasondmoss/ab60c3aa1a7e3b75c9378c2dacf5ad21 to your computer and use it in GitHub Desktop.
Polyfill Methods for Internet Explorer 11 and below.
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
/** | |
* Polyfill for `Element.prototype.closest()` | |
* | |
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest | |
*/ | |
if (!Element.prototype.closest) { | |
Element.prototype.closest = function (s) { | |
"use strict"; | |
var el = this; | |
do { | |
if (el.matches(s)) { | |
return el; | |
} | |
el = el.parentElement || el.parentNode; | |
} while (el !== null && el.nodeType === 1); | |
return null; | |
}; | |
} | |
/* <> */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment