JavaScript DOM Scripting By Example Adding and Removing Names RSVP Checkbox

Maxim Melnic
Maxim Melnic
4,176 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:"responded");

1 Answer

Steven Parker
Steven Parker
153,115 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!