Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Traversal Review

ParentNode

Why can't we use parentNode to the same elements few times?

1 Answer

We can, I think you misunderstood the question. Try this in your browser console on this page:

let test = document.getElementById('answer-body-all').parentNode.parentNode.parentNode;
// undefined
test
// <form>

Tried, but I still don't understand what's going on...

This is showing that you can start at an element 'answer-body-all' (which is the reply section on this page), then select 3 parent elements above and store that in a variable.

Then by typing the variable (test) the console outputs the element you found by using multiple parentNode's