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

Maxim Melnic
Maxim Melnic
4,178 Points

className = "" Seriously? much better to use classList!

Hi, but if for example this list have other classes?? You simply delete them or delete them first. I don't know. But it's best to remove current class.

for this we can use classList method:

event.target.parentElement.parentElement.classList.remove("responded");

1 Answer

Steven Parker
Steven Parker
231,236 Points

I'd agree that's a "best practice" method for general purposes. In the video, they took advantage of the fact that no other classes are being used so just making the className empty is an effective shortcut.

But you make an excellent point about using shortcuts — in real-life projects, one must be extra careful not to "cut corners" where it might impact code that may be added later in the life of the software.

Happy coding!