JavaScript · Junior · Question 70 of 75
What does el.classList.toggle("open") do?
- ✓Correct answer: Adds the class if missing, removes it if present, and returns whether it is now present
- 2Replaces all classes with
open - 3Toggles the element's visibility
Explanation
A second argument forces the state: toggle("open", isOpen). Using classList is safer than editing the className string by hand.