Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Adding and Removing Names RSVP Checkbox

class is not getting added, and nothing changes when checkbox is checked

const form = document.querySelector('#registrar');

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

form.addEventListener('submit', (event) => {
    const text = input.value;
    input.value = '';

    const li = document.createElement('li');
    li.textContent = text;

    const label = document.createElement('label');
    label.textContent = 'Confirmed';
    const checkbox = document.createElement('input');
    checkbox.type = 'checkbox';


ul.addEventListener('change', (event) =>{
    const checkbox = event.target;
    const checked = checkbox.checked;
    const listItem = checkbox.parentNode.parentNode;

        listItem.className = 'responded';

        listItem.className = '';

The code seems not to work for me, when I click on the checkbox nothing happens. Any help would be appreciated.

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, babasariffodeen! I took the code you provided in the question above and put it in the workspace, and it works for me. The class "responded" is assigned according to the dev tools and a sort of teal border appears around the box. I also see no errors in the console.

So here are some things to check:

  • It seems silly, but we all forget to save our work sometimes. Make sure your work is saved.
  • Once confirmed as saved, refresh the page.
  • If this is still not working, your browser may be loading in cached data. Try clearing your browser cache and see if that helps or launch the preview in a private browsing tab.

Hope this helps! :sparkles:

Thanks Jennifer! I just tried clearing browser cache and it worked! :)