Created
July 24, 2015 13:42
-
-
Save stasgavrylov/07d63d7d32d99321ee00 to your computer and use it in GitHub Desktop.
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
Element.prototype.closest = function(selector) | |
{ | |
var element = this; | |
do if (element.matches(selector)) return element; | |
while (element = element.parentElement); | |
return null; | |
}; | |
Element.prototype.matches = (function($) | |
{ | |
return $.matchesSelector | |
|| $.webkitMatchesSelector | |
|| $.mozMatchesSelector | |
|| $.msMatchesSelector | |
|| $.oMatchesSelector; | |
})(Element.prototype); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment