Skip to content

Instantly share code, notes, and snippets.

@muralikrishnat
Created May 29, 2019 18:09
Show Gist options
  • Save muralikrishnat/af0f256b6ba4fd617f7e54f0e48503c2 to your computer and use it in GitHub Desktop.
Save muralikrishnat/af0f256b6ba4fd617f7e54f0e48503c2 to your computer and use it in GitHub Desktop.
To check element is descendant of parent element
/* 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