How to add or remove classes from HTML element

Or even toggle if necessary.

January 27, 2021

Code 💻

1 min read

You can add or remove (or even toggle) classes from HTML element by

element.classList.add('foo');
element.classList.remove('foo');
element.classList.toggle('foo');