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

Code Challenge: Stage 3 Traversing and Manipulating the DOM with JavaScript. Changing Classes

Can anyone help with this 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"



//Toggle the class "live"

3 Answers

Hi Brian,

For this challenge you need to use the classList property which exists as of IE10+ and has the following methods.

  • add
  • contains
  • remove
  • toggle

For the challenge we want to use the add method as per the below example.

anchor.classList.add('selected');

Brian,

Can you post the code that you've tried thus far that isn't working for you, so we can help explain where things might've gone wrong? That will do more for you than simply giving you the answer.

Erik

Apologies, for delayed reply. I was missing the method add.

Thanks Chris and Erik