I have a little big problem with my code, i have a list that load with ajax and i want to add this code for each class on that list so here is my code
$(document).ajaxComplete(function() {
$('#contactomodal').on('hide.bs.modal', function() {
$('#contactomodalabierto').empty();
});
if ($('.pflist-item-inner .pfquicklinks').parent().find('.informacion').length > 0) {} else {
$('.pflist-item-inner .pfquicklinks').prepend('<a title="" id="" class="informacion" data-original-title="Informacion" data-toggle="modal" data-target="#contactomodal"><i class="fas fa-info"></i> Contacte</a>');
}
$('.informacion').each().click(function() {
if ($(this).attr('id') === '') {
var id = $(this).nextAll('.pfquickview').attr('data-pfitemid');
} else {
var id = $(this).attr('id');
}
var action = 'contactomodal';
$.ajax({
url: my_ajax_object.ajax_url,
data: {
id: id,
action: action
},
success: function(data) {
$('#contactomodalabierto').html(data);
return false;
}
});
});
});
The problem is when i click on .informacion
class, at the 2nd or 3rd click the function repear several times and always is reloading the ajax. If i change the .ajaxComplete
for .ready
my code doesn't work. Any idea?