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

Why is nothing happening?

I have written all this code down, and the class has been changed to 'responded' but the list item does not get any styling can someone help and explain why this is?

const form = document.querySelector('#registrar');
const input = form.querySelector('input');
const ul = document.querySelector('#invitedList');
const li = document.createElement('li');

form.addEventListener('submit', function submit(name) {
  name.preventDefault();
  const text = input.value;
  input.value = '';
  li.textContent = text;
  const label = document.createElement('label');
  label.textContent ='Confirmed';
  const checkbox = document.createElement('input');
  checkbox.type = 'checkbox';  
  label.appendChild(checkbox);
  li.appendChild(label);
  ul.appendChild(li);
  input.value = '';
});

ul.addEventListener('change', function styling(e) {
  const checkbox = e.target;
  const checked = e.checked;
  const listItem = checkbox.parentNode.parentNode;
  if (checked) {
    listItem.clasName = 'responded';
  } else {
    listItem.className = '';
  }
});

1 Answer

There are two things to fix in ul.addEventListener

const checked = e.checked;

should be

const checked = e.target.checked;

and

listItem.clasName = 'responded';

should be

listItem.className = 'responded';

Thank you! Can't believe I spent so much time trying to find out what was wrong only to find out they were typos! :-)