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 trialMaksym Novikov
4,580 PointsParentNode
Why can't we use parentNode to the same elements few times?
1 Answer
richporter
16,727 PointsWe 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>
Maksym Novikov
4,580 PointsMaksym Novikov
4,580 PointsTried, but I still don't understand what's going on...
richporter
16,727 Pointsrichporter
16,727 PointsThis 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