Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Add a CSS Class

DOM & Eventseasy

Course · Section 7: JavaScript in the Browser: DOM and Events · Lecture 76: Selecting and Manipulating Elements

The page has a `<div id='box'>`. Add the class `active` to it.

Sample tests

Input: #box has the 'active' class
Output: assertion passes

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Overwriting className wipes any existing classes; classList.add is additive.

Learning resources

  • MDN: Element.classList
Approach & explanation (try first)

classList.add appends the class without disturbing others.

Loading...
⌘/Ctrl + Enter

Run your code to see results.