IMUXIxD
IMUXIxD

Reputation: 1227

Switch between two css classes on click

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.

Upvotes: 0

Views: 871

Answers (1)

Fresheyeball
Fresheyeball

Reputation: 30015

 $('.a').on('click',function(){
      $(this).toggleClass('a b');
 });

Upvotes: 4

Related Questions