js is element descendant
snippet in javascript

javascript Check if an element is a descendant of another

user5517

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

js is element descendant

user9884

/* 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
}