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 Using previousElementSibling and insertBefore

James Thompson
James Thompson
2,475 Points

Question about using syntax to grab parent/child elements in DOM.

In the video Guil uses this set of syntax:

if (event.target.tagName == 'BUTTON') { if(event.target.className == 'remove') { let li = event.target.parentNode; let ul = li.parentNode;

From what I under stand the event.target.className refers to the click event on the remove button.

Looking at event.target.ParentNode; This targets the parent of the button node. The <li> element.

<li>amethyst <button class = "remove">Remove</button> </li>

I am getting confused on what li.parentNode; does exactly?

1 Answer

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Hey James Thompson , you're correct in your understanding. li.parentNode selects the parentNode of the li which is a ul