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.
$('.a').on('click',function(){
$(this).toggleClass('a b');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.