Stuck on Adding and Removing Classes


#1


https://www.codecademy.com/courses/web-beginner-en-v6phg/1/1?curriculum_id=50a3fad8c7a770b5fd0007a1

I have tried tweaking this and am about to break something in frustration! I'm sure it's glaring me in the face, but I just can't see it. Please could someone point out where I'm going wrong? Thanks.
Oops, try again. It looks like your #text doesn't have the class .highlighted. Check the Hint if you need help!


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


#2

Hi @hfitton,

When you use the addClass() and removeClass() functions, jQuery knows that you are going to send them a className so you must not include a . in the className.


#3

I've removed the full stop . from the addClass and get the same result.


#4

I tried removing the . from highlighted too, also did nothing.


#5

You should be removing the . from the className, not the function name. Please repost your code showing the changes.


#6

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

#7

Resolved.

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

#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.