George George - 7 months ago 18
Javascript Question

toggleClass not working in ajax

Hello Im new on stackoverflow, i have this GET method its work fine i mean i get a respone from server but i toggleClass is not working i dont know why ?

this is my code:

$("#form1").on("click", function() {
var user = $("#form1 input.user").val();
$.ajax({
url: "admin.php?user=" + user,
type: "GET",
beforeSend: function() {},
success: function(res) {
$("#results").html(res);
$("#results .name").toggleClass('.active');
}
});
});

Answer

you dont need a dot just remove it from your code change

$("#results .name").toggleClass('.active');

to

$("#results .name").toggleClass('active');