Last active
February 28, 2019 16:08
-
-
Save andrewluetgers/027221b5f7a1cab22b637382c796385d to your computer and use it in GitHub Desktop.
Select a parent node that matches a query selector.
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
export default function selectParent(el, selector) { | |
let parent = null, | |
p = el.parentNode, | |
pp = p.parentNode, | |
sel = pp ? pp.querySelector(selector) : null, | |
done = !pp || sel === p; | |
console.log(selector, el) | |
return done ? sel : selectParent(p, selector); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment