0

I was wondering how to do something more efficiently in jQuery and that is switch a class to another class on click on #trigger.

So on odd clicks, class a ( .a ) will be given to all <nav>s in the document and then on even clicks, class a ( .a ) will be remove / switched-out and replaced with class b ( .b ).

The only way i could think about doing this is by adding the new class and removing the current class, but i'm sure there has to be a more efficient way of doing this.

Rafay
  • 30,950
  • 5
  • 68
  • 101
IMUXIxD
  • 1,223
  • 5
  • 23
  • 44

1 Answers1

4
 $('.a').on('click',function(){
      $(this).toggleClass('a b');
 });
Fresheyeball
  • 29,567
  • 20
  • 102
  • 164