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

Is there an error in the code?

Shouldn't there be 2 times .parentNode in the last part of code? Seems, that having it once (like in the video) doesn't remove the whole box only some of the elements.

const li = e.target.parentNode.parentNode;

ul.addEventListener('click', (e) => {
  if (e.target.tagName === 'BUTTON') {
    const li = e.target.parentNode.parentNode;
    const ul = li.parentNode;
    ul.removeChild(li);
  }
});

1 Answer

Steven Parker
Steven Parker
231,248 Points

The parent of the button is the list item, so there should only be one "parentNode" when creating the "li" reference.

You didn't refer to the video, but I'm guessing that the intent of the button is to remove only the list item the button is on, not the whole list.