We can add class values to an
element using the classList
property.
Look at the following example
to see the classList
property
in the console:
The classList
property returns
a list of all the class attributes
of the h1
element.
In the console for the above code
we can see the class name highlight
.
We can add class names to this list
using the add
method.
Let us take a look at the following
example to understand how to add classes:
As we can see see in the console,
we get two class names now.
The highlight
and the complete
classes are both now present on
the h1
element.