To add/remove several classes in one single instruction with classList and JavaScript, we can call add
or remove
with all the classes we want to add or remove.
For instance, we write
elem.classList.add("first", "second", "third");
to call elem.classList.add
to add the first, second, and third classes.
Likewise, we write
elem.classList.remove("first", "second", "third");
to call elem.classList.remove
to remove the first, second, and third classes.