jquery toggle class add remove code example
Example 1: 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 2: toggle class jquery
toggleClass
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() {}
});
}