forloop to check if parent has parent code example
Example: js is element descendant
/* 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
}