js is element descendant

JavaScript
const isDescendant = (child, parent) => parent.contains(child);/* if you want to check deeply nested children*/
const isDescendant = (el, parentId) => {
  let isChild = false

  if (el.id === parentId) { //is this the element itself?
    isChild = true
  }

  while (el = el.parentNode) {
    if (el.id == parentId) {
      isChild = true
    }
  }
  return isChild
}
Source

Also in JavaScript: