Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

How to select a parent node and store it in a constantDiv?

I'm having trouble finding the answer to a quiz question. Here is the question: In the code below, the constant div contains a reference to a DOM element. Select its parent node and store that in the constant parentOfDiv

const div = document.querySelector('div'); const parentOfDiv =

4 Answers

I got the right answer with: const parentOfDiv = div.parentNode;

In the code below, the constant div contains a reference to a DOM element. Select its parent node and store that in the constant parentOfDiv const div = document.querySelector('div'); const parentOfDiv =

The parentNode property of div can access its parent. what will be the parent node for constantDiv plz help me

Jonathan Rhodes
Jonathan Rhodes
8,086 Points

const parentOfDiv = div.parentNode;

Jonathan Rhodes
Jonathan Rhodes
8,086 Points

The parentNode property of div can access its parent.

Could someone Explain me, how its really works? Thanks for everyone hlep.