What's wrong with this JQuery code?

I just started to practice JQuery, and now can't figure out why clicking the button does not change the class:
$('.button-red').click(function(){
$(this).removeClass('button-red');
$(this).addClass('button-blue');
});
July 8th 19 at 16:39
3 answers
July 8th 19 at 16:41
Solution
Try to wrap everything in :
$(document).ready(function() {

});
Work, once wrapped, thank you! - moses.Hamm commented on July 8th 19 at 16:44
July 8th 19 at 16:43
Solution
You have the selector not the selected. Here is the syntax.
$(selector).removeClass(class). Taken here

If you want when you click the styles have changed, use toggleClass

Example
Yes, toggleClass is better suited for this task, thanks! - moses.Hamm commented on July 8th 19 at 16:46
July 8th 19 at 16:45
Yes it works. www.bootply.com/Djrm3GjWrn
You just plugged in jQuery?

Open the console and see whether there you have the error $ is not defined
So, and with jquery 2.x version put - moses.Hamm commented on July 8th 19 at 16:48
So, most likely you did not connect or it connects later in your script. Check the connection and do as you said Askerov - moses.Hamm commented on July 8th 19 at 16:51

Find more questions by tags jQuery