Solution Review: Is a Child?
This lesson will explain the solution to the problem in the previous lesson.
We'll cover the following...
Solution #
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;elsechild = child.parentNode}return false}
It takes two parameters, the parent
and the child
element. First, the function checks if the child
has a ...