6. Adding and Removing classes


#1

Anyone who can tell me why this code below is not working?

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

I don't understand why the class is not being added to the div element #text


#2

Hi Michelle,

Please see this post explaining why you can't have a dot (.) in addClass()'s parenthesis (()) :slight_smile::


Adding and Removing Classes
#3

Ahh...thank you so much! Now I understand.


#6

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