1$(".nav-link").click(function () {
2 // If the clicked element has the active class, remove the active class from EVERY .nav-link>.state element
3 if ($(this).hasClass("active")) {
4 $(".nav-link").removeClass("active");
5 }
6 // Else, the element doesn't have the active class, so we remove it from every element before applying it to the element that was clicked
7 else {
8 $(".nav-link").removeClass("active");
9 $(this).addClass("active");
10 }
11});
1$('.click-class').click(function() {
2 $('.class-toggle').toggle();
3 $('.class-toggle').toggleClass('add-class');
4})
1// add class [class-name] if condition is true
2// or else remove it
3$('#foo-bar').toggleClass('class-name', condition)