![Add a Class to an Element](https://javascriptsource.com/wp-content/uploads/2021/08/Add-a-Class-to-an-Element-702x526.jpg)
To add a class to an element, you use the classList
property of the element. Suppose you have an element as follows:
<div>Item</div>
To add the box class to the <div>
element, you use the following:
const div = document.querySelector('div');
div.classList.add('box');
It’s possible to add multiple classes. The following adds three classes to the <div>
element:
const div = document.querySelector('div');
div.classList.add('box','primary','rounded');