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 DOM Scripting By Example Adding and Removing Names RSVP Checkbox

Brian Patterson
Brian Patterson
19,588 Points

Not sure if the responded class is working.

When I run this in the browser nothing seems to change in the box.

//Remember, list item elements are children of UL elements,
//creating the change event handler.
ul.addEventListener('change', (e) => {
  // console.log(e.target.checked);
  //And now let's get a reference to the
  //check box itself here on the first line of
  const checkbox = event.target;
  //Once we have the value of the checkbox it will be store in checked.
  const checked = checkbox.checked;
  /*
  Now since we'll change the
  class of the list item, when the check box is checked.
  We need a reference to the list item.
  List item is the checkbox is grandparent because
  the label is a child of list item
  So we can traverse to the list item by calling parent node twice
  */
  const listItem = checkbox.parentNode.parentNode;

  //change the class name
  //if true then change class name.
  if (checked) {
    list.className = 'responded';
  } else {
    listItem.className = '';
  }
});

Just wanted to check I have got everything right.

1 Answer

You mistyped the listItem variable in the if statement near the end. Should be:

  if (checked) {
    // You had 'list' instead of 'listItem'
    listItem.className = 'responded';
  } else {
    listItem.className = '';
  }

You bet!