Created
June 11, 2019 09:06
-
-
Save bitsprint/16f50ef435bb843f28c502687379a51f to your computer and use it in GitHub Desktop.
Climbs the DOM to find a parent element
This file contains hidden or 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
var el = $('#some-element'); | |
var selector = '#some-elements-parent-further-up-the-dom'; | |
for ( ; el && el !== document; el = el.parentNode ) { | |
if ( el.matches( selector ) ) return el; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment