Skip to content

Instantly share code, notes, and snippets.

@DevCodo
Created June 19, 2019 06:12
Show Gist options
  • Select an option

  • Save DevCodo/e98be58b0748e40abb7cf497f3311135 to your computer and use it in GitHub Desktop.

Select an option

Save DevCodo/e98be58b0748e40abb7cf497f3311135 to your computer and use it in GitHub Desktop.
(function() {
if (!Element.prototype.matches) {
// определяем свойство
Element.prototype.matches = Element.prototype.matchesSelector ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector;
}
// проверяем поддержку
if (!Element.prototype.closest) {
// реализуем
Element.prototype.closest = function(css) {
var node = this;
while (node) {
if (node.matches(css)) return node;
else node = node.parentElement;
}
return null;
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment