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

Igor Pavlenko
Igor Pavlenko
12,925 Points

hi wouldn't it be easier to change the class like below?

checkBox.addEventListener('click', () => { li.classList.toggle('responded'); });

1 Answer

Steven Parker
Steven Parker
229,670 Points

In some situations, such as where a push button was used, that might be the best choice. But here, it doesn't guarantee staying in sync with the checkbox like the original code does.

If you did not want to disturb other classes that might be applied to the element but still guarantee sync, you could use the ".add()" and ".remove()" methods.