What exactly does this code do

Based on this answer - how can I change classes when clicked can someone explain to me what exactly the code below does?

$("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.

+3
source share
1 answer

First he finds all the elements a(links).

He sets his actions by clicking on a function that:

  • checks if this link currently has a yyCSS class .

  • If it is not, then it disables the class yyfor everything that has it, and switches xxto those used for the class yy.

  • After that it switches the classes yyand xxthe link that was clicked.

+11

Source: https://habr.com/ru/post/1766512/


All Articles