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

Greg Schudel
Greg Schudel
4,090 Points

Store the value within the target...why?

This "references the checkbox to itself" If I take it away it simply doesn't work. Why do I need to reference it to itself?

ul.addEventListener('change' , (e) => {

  const checkbox = event.target; // references to checkbox itself
  const checked = checkbox.checked;
  const listItem = checkbox.parentNode.parentNode;

if (checked){

  listItem.className = 'responded';
}
  else{
    listItem.className = '';


  }

});

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You may have added 10 separate people to that list. In that case, there will be ten separate checkboxes. Inside the event listener, it needs to know which checkbox was checked. You could, potentially reference other checkboxes, but we specifically want the checkbox we just interacted with which is the event.target. The target of the event is the checkbox we're wanting to do something with.

Hope this helps! :sparkles: