Solution Review: Is a Child?

This lesson will explain the solution to the problem in the previous lesson.

Solution #

Console

Explanation #

Let’s discuss the JavaScript code for isChild.

Press + to interact
function isChild(parent, child){
while(child.parentNode){
if(child.parentNode == parent)
return true;
else
child = child.parentNode
}
return false
}

It takes two parameters, the parent and the child ...

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.