I want to add this function after a .ajaxComplete, but every time an ajax happens, this bolt executes a number of times equal to the amount of ajax that happened.
For example, if I click the button in the .chPlus class the first time, the console prints "more" once;
When I click again, the console prints two more times than the first, then 3 times, and so on.
$(document).ajaxComplete( function(){
$('.chButton').click( function(){
if($(this).hasClass('chPlus')){
console.log("mais");
} else {
console.log("menos");
}
});
});
I found a solution in the following topic: link
The solution would be the .bind function in document.ready with the ajax complete function. but I do not know how to do it or I do not understand it.
Here's my implementation:
jQuery(document).bind( "ajaxComplete", function() {
jQuery('.chButton').click( function(){
if(jQuery(this).hasClass('chPlus')){
alert("mais");
} else {
alert("menos");
}
});
});