7. Toggling Class not accepting my answer


#1

$(document).ready(function() {
$('div#text').click(function() {
$('div#text').toggleClass('highlighted');
});
});

I don't understand what I am doing wrong. Toggle is also working, but not allowing me to pass next level.


#2

I've solved the problem. I've removed 'div' section.

$(document).ready(function() {
$('#text').click(function() {
$('#text').toggleClass('highlighted');
});
});


#3

Thanks for posting this. I had a similar problem and you answered it for me.


#4

This section seemed so easy too. Change one word is all it says- and it doesn't work. Thanks for figuring this out for us.


#5

But why did changing $('div#text') to $('#text') work? I would think that they both would select the same element since there's only one div with an id of text. It's weird that just changing .addClass to .toggleClass didn't work


#6

Seems like the answer checker is looking for a very specific piece of code: $("#text").toggleClass("highlighted")

I defined a variable to hold $("#text") and it wouldn't accept my answer despite it functioning properly. There's nothing wrong with your answer, it's just that the answer checker is looking for one particular solution (I think).


#7