Created
May 29, 2019 18:09
-
-
Save muralikrishnat/af0f256b6ba4fd617f7e54f0e48503c2 to your computer and use it in GitHub Desktop.
To check element is descendant of 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
/* Returns true incase of `child` element is child element of `parent` element */ | |
function isDescendant(parent, child) { | |
let node = child.parentNode; | |
while (node != null) { | |
if (node == parent) { | |
return true; | |
} | |
node = node.parentNode; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment