How to add a class to the html element with JavaScript?

Spread the love

To add a class to the html element with JavaScript, we call the classList.add method.

For instance, we write

document.documentElement.classList.add("myCssClass");

to get the html element with document.documentElement.

Then we call classList.addto add themyCssClass` to it.

Leave a Reply

Your email address will not be published. Required fields are marked *