Last active
December 15, 2015 03:29
-
-
Save KoryNunn/5194180 to your computer and use it in GitHub Desktop.
Simple closest element.
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 closest(target, selector){ | |
while(target && target.parentNode && Array.prototype.slice.apply(target.parentNode.querySelectorAll(selector)).indexOf(target)<0){ | |
target = target.parentNode; | |
} | |
return target === document ? null : target; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment