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 Changing Classes

Keith Doyle
Keith Doyle
25,973 Points

Interactive Web Pages - classList.toggle isn't working

For the challenge task 2, I'm inputting what I'm fairly certain to be the correct answer, but it won't pass. I even tried copying/pasting the example from MDN for classList.toggle and it doesn't work.

// Toggle the class "live" on the anchor element
anchor.classList.toggle("live");
Keith Doyle
Keith Doyle
25,973 Points

Forgot to mention, the message I receive is "You didn't call the toggle() method."

Keith Doyle
Keith Doyle
25,973 Points

HUZZAH!

The first step passed even though I used className instead of classList.add but the error happened on the second stage saying I didn't use the toggle() method. Weird.

7 Answers

anchor.classList.toggle("live");

"live" should have a lowercase.

James Nelson
James Nelson
23,956 Points

I got it working. It was the same as the above. The engine must of been a bit buggy.

Kelvin Knighton
Kelvin Knighton
6,168 Points

I think it's still buggy, because i'm trying to pass it now

Alexander Stanuga
Alexander Stanuga
11,999 Points

I just tried it again, and discovered that I had used CAP "L" for "live" .

Solved my problem

Worked for me. Exactly what line is your code on? Sometimes, the engine can be a little finicky and won't accept code unless it's in the perfect spot.

Keith Doyle
Keith Doyle
25,973 Points

I've put it on line 8, line 9, indented it. Nothing seems to work.

James Nelson
James Nelson
23,956 Points

I am getting the same issue.

Keith Doyle
Keith Doyle
25,973 Points

Can you post your code? That'll help.

Alexander Stanuga
Alexander Stanuga
11,999 Points

I'm having the same issue here, driving me crazy.

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

//Add the class to the classList "selected"

 anchor.classList.add("selected"); 

//Toggle the class "live"

anchor.classList.toggle("Live");

Can anyone tell me what I'm doing wrong?

Yaa you are doing it correctly but try to put "Live" to small caps