Created
July 3, 2015 09:22
-
-
Save Sjeiti/1ee7c1054dca8ef6004e to your computer and use it in GitHub Desktop.
querySelectorParents: traverse an elements parentNodes until the selector is matched
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 querySelectorParents(elm,selector){ | |
var result; | |
while ((elm=elm.parentNode)&&elm!==document) { | |
if (elm.matches(selector)) { | |
result = elm; | |
break; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment