classList
noun
say it: “KLAS-list” /ˈklæslɪst/
An element's CSS classes, with methods to add, remove and toggle them.
What is classList in JavaScript?
classList — An element's CSS classes, with methods to add, remove, toggle and check (contains) them one at a time. Changing a class lets the stylesheet do the styling, instead of setting styles in JavaScript.
const button = document.querySelector("#favorite");
button.classList.toggle("active");
In a sentence
- “Clicking the star calls classList.toggle("active") to color it in.”
Level: Apprentice · More JavaScript terms at this level
Updated