Sometimes, we want to add another class to a div with JavaScript.
In this article, we’ll look at how to add another class to a div with JavaScript.
How to add another class to a div with JavaScript?
To add another class to a div with JavaScript, we call classList.add.
For instance, we write
document.getElementById("hello").classList.add("someClass");
to select the element with getElementById.
Then we call its classList.add method to add the someClass class to it.
Conclusion
To add another class to a div with JavaScript, we call classList.add.