JS Basic Tutorial
The classList
property offers methods like add
, remove
, toggle
, and contains
to work with classes efficiently.
The add()
method adds one or more classes to an element.
Try it yourself
The remove()
method removes one or more classes from an element.
Try it yourself
The toggle()
method adds a class if it is not present, and removes it if it is.
Try it yourself
The contains()
method checks if an element has a specific class.
Try it yourself