[Home] > Snippets  > Browser  > DOM  >  Check if an element is a descendant of another

Check if an element is a descendant of another

JavaScript

const isDescendant = (child, parent) => parent.contains(child)

TypeScript

const isDescendant = (child: Node, parent: Node): boolean => parent.contains(child)