JavaScript DOM Scripting By Example Adding and Removing Names RSVP Checkbox

Siddharth Pandey
Siddharth Pandey
4,069 Points

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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 49,791 Points

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';
Siddharth Pandey
Siddharth Pandey
4,069 Points

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