JavaScript · DOM and events

classList

Manages classes without touching the class attribute string. Supports add, remove, toggle and contains.

Syntax
el.classList.add("active")

Example

Try it

More in this group

addEventListener append closest createElement dataset element.style Event delegation Event object

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course