To add a class to an element in Javascript, you can use the classList
property of the element.
index.tsx130 chars6 lines
In this example, we first select the element using document.querySelector()
, and then use the classList.add()
method to add the class my-class
to the element. You can replace my-class
with the name of the class you wish to add.
gistlibby LogSnag