Last active
January 5, 2016 08:50
-
-
Save teodragovic/acafe7e2af47d96e81a1 to your computer and use it in GitHub Desktop.
closest() polyfill
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
(function (ELEMENT) { | |
ELEMENT.matches = ELEMENT.matches || | |
ELEMENT.mozMatchesSelector || | |
ELEMENT.msMatchesSelector || | |
ELEMENT.oMatchesSelector || | |
ELEMENT.webkitMatchesSelector; | |
ELEMENT.closest = ELEMENT.closest || function closest(selector) { | |
var element = this; | |
while (element) { | |
if (element.matches(selector)) { | |
return element; | |
} else { | |
element = element.parentElement; | |
} | |
} | |
return null; | |
}; | |
}(Element.prototype)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment