How to add/remove several classes in one single instruction with JavaScript classList?

Spread the love

Sometimes, we want to add/remove several classes in one single instruction with JavaScript classList.

In this article, we’ll look at how to add/remove several classes in one single instruction with JavaScript classList.

How to add/remove several classes in one single instruction with JavaScript classList?

To add/remove several classes in one single instruction with JavaScript classList, we can pass in a list of class strings.

For instance, we write

elem.classList.add("first", "second", "third");

to call add to add the 3 classes listed in the arguments.

Conclusion

To add/remove several classes in one single instruction with JavaScript classList, we can pass in a list of class strings.

Leave a Reply

Your email address will not be published.