classList Quiz
Multiple Choice Easy
Question
Which classList method toggles a CSS class on an element?
Hint
toggle adds the class if absent, removes it if present.
Explanation
classList.toggle(className) adds the class if it is not present and removes it if it is present — a convenient way to toggle visibility, active states, etc. Other useful classList methods include add(), remove(), contains(), and replace().
Related Resources
Related Lessons
- DOM
Learn about classList.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.