Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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"

Help?

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:

 anchor.classList

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

anchor.classList.add();

Step 3: Put the value selected inside the add method

anchor.classList.add("selected");

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

1 Answer

anchor.classList.add("selected");