toggle class jquery code example
Example 1: toggle class javascript and jquery
$('.click-class').click(function() {
$('.class-toggle').toggle();
$('.class-toggle').toggleClass('add-class');
})
Example 2: toggle jquery remove others
$(".nav-link").click(function () {
if ($(this).hasClass("active")) {
$(".nav-link").removeClass("active");
}
else {
$(".nav-link").removeClass("active");
$(this).addClass("active");
}
});
Example 3: jquery toggle class
$( "#foo" ).toggleClass( 'className', addOrRemoveOptional );
Example 4: jquert toggleClass condition
$('#foo-bar').toggleClass('class-name', condition)
Example 5: toggle class jquery
toggleClass