A. The class name should be 'dark-mode', not 'dark'.
B. The selector 'html' is incorrect; should be 'body'.
C. It adds and removes 'dark' class immediately, so no visible change.
D. The event listener should be 'addEventListener', not 'onclick'.
Solution
Step 1: Analyze the toggle logic
The code adds then immediately removes the dark class on the same element in one function call.
Step 2: Effect on the page
Because add and remove happen instantly, the class never stays applied, so no dark mode effect is visible.
Final Answer:
It adds and removes 'dark' class immediately, so no visible change. -> Option C
Quick Check:
Immediate add and remove cancels out [OK]
Hint: Toggle class once; don't add and remove immediately [OK]
Common Mistakes:
Thinking 'onclick' is invalid
Using wrong selector for dark mode
Confusing class name with 'dark-mode'
5. You want to save the user's dark mode preference so it stays after page reload. Which JavaScript approach correctly implements this with Tailwind CSS?
1. On toggle, add/remove 'dark' class on <html>.
2. Save preference in localStorage.
3. On page load, read preference and set 'dark' class accordingly.
Which code snippet correctly sets dark mode on page load?