Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Changing Classes

Jacob Tennyson
Jacob Tennyson
6,240 Points

Last Challenge!!

On line 5 of app.js, use the classList property on the anchor to add a new class of "selected" to it.

var anchor = document.querySelector("a");

//Add the class to the classList "selected"

    var anchor = document.classList.contains("selected");

//Toggle the class "live"


Robert Karlsson
Robert Karlsson
8,021 Points

As the instructions sais you need to use the classList poperty of the anchor and add the class "selected". All elements have properties and classList is one of them.

Step 1: Use the classList property:


Step 2: Call it's add method to add a class


Step 3: Put the value selected inside the add method


You can read more about classList at MDN Hope this helps!

1 Answer