How to add or remove classes from html element

I wrote this blog post so I can copy paste it into my dev works.

August 05, 2022 Code

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');

Invely's