Skip to content

Instantly share code, notes, and snippets.

@jasondmoss
Last active December 10, 2019 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasondmoss/ab60c3aa1a7e3b75c9378c2dacf5ad21 to your computer and use it in GitHub Desktop.
Save jasondmoss/ab60c3aa1a7e3b75c9378c2dacf5ad21 to your computer and use it in GitHub Desktop.
Polyfill Methods for Internet Explorer 11 and below.
/**
* 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