classList API Playground

The teacher works on the class’s real menu card: add, remove, toggle, replace and contains run on the element, the board writes its tokens and class…

Why it matters

Toggling classes is the main way JS changes how things look: open a menu, the active tab, a dark theme. classList makes it safe (no duplicates, no lost spaces) and short: toggle('open', isOpen) replaces an if/else.

The key idea

classList is a list of tokens, className is just a string

Common mistakes

Try it in this playground