From the course: JavaScript: Enhancing the DOM

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Solution: Animal tree traversal

Solution: Animal tree traversal

(upbeat music) - [Instructor] Great job on attempting the challenge. Let's go through one possible solution. The first task was to find parent element of a cat. So step one would be to select the cat element, and there's many ways to do it. Here's how I did it. Then I used the .parent noise to find a parent, and I logged that. The next exercise was to grab all the children of the cat's parent. So in order to do that, we used the .children property and to be able to use the forEach, I converted this to an array. Then lastly, we had to identify the cat's parents' next sibling. We did this with the nextElementSibling property. Remember, there can be multiple ways to solve these tasks. The key is to understand the relationship between elements in the DOM and how to navigate them using JavaScript. If you get the same results, you probably did it right.

Contents