Based on this answer – how to change classes on click
can somebody explain me what exactly the code below is doing?
$("a").click(function() {
var $this = $(this); // this is just for performance
if(!$this.hasClass('yy'))
$('.yy').toggleClass("yy").toggleClass("xx");
$this.toggleClass("yy").toggleClass("xx");
});
I mean the last two lines.
First, it finds all of the
aelements (links).It sets their on-click actions to a function which:
checks to see if that link currently has the
yyCSS class.If it doesn’t, then it turns off the
yyclass on everything which has it and toggles thexxon those that used to have theyyclass.After that, it toggles the
yyandxxclasses on the link that was clicked.