jquery toggle add remove class 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: toggle one class add and one class remove same time and after click remove class add and add class remove jquery
function viewPastClass(id) {
var class_date = $('#pastclassdata' + id).val();
$.ajax({
type: 'GET',
url: '{{ url("/teacher/class/viewPastClass") }}',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: {
'class_date': class_date,
},
success: function(result) {
$('#plclasses').show(class_date);
},
error: function() {}
});
}