0
Hello, I am not able to use addClass when I give a replay on my page using ajax. What happens is that it adds the class to my html element for a moment, but the behavior is as if the page is being loaded, so nothing happens. I’m making a pagination.
$('.waves-effect a').click(function(e) {
e.preventDefault();
var url = $(this).data('href');
$.ajax({
type: "GET",
url: url,
success: function(response) {
$('#form').html(response)
},
complete: function() {
$(".waves-effect").click(function() {
$(this).addClass("active");
});
}
});
});
<li class="waves-effect"><a data-href="webmail.php?page=<?=$i?>"><?=$i?></a></li>
I’m kind of a layman in Jquery, so I appreciate all your help.
I tested it here and it’s ok. Have you tried removing this event
$(".waves-effect").click(function() {}
? Leave only the$(this).addClass("active");
in thecomplete
?– Valdeir Psr
I need to add the class "active", only where in the element clicked (this). I tried to remove and did not function =/
– gemerich
Try to do as Fernando posted below. The
complete
will only add the classactivity
when the request is completed.– Valdeir Psr