I have a problem, it turns out that I have a system to approve and disapprove posts, and when I click on disapprove, I change the class so that the click event can react to it, but it seems that once the DOM has been changed at runtime, I can't get rid of the old event click and join the new one (when you change classes, there is a click event). I have tried "unbind" and "bind" but like a snowball, I don't know...
<a href="javascript:void(0)" id="{{ $temas->id }}" class="aprobartema text-green-500 hover:text-green-600 hover:underline mr-3">Aprobar</a>
<a href="javascript:void(0)" id="{{ $temas->id }}" class="desaprobartema text-yellow-500 hover:text-yellow-600 hover:underline mr-3">Desaprobar</a>
$('.aprobartema').click(function(){
var id = $(this).attr('id');
var url = '{{ route("tema.aprobar") }}';
$.ajax({
type: 'POST',
url: url,
data:
{
"id": id,
"_token": "{{ csrf_token() }}",
},
success: function(response) {
let i=response.id;
let nupositivo= parseInt($('#p-'+i).text(), 10);
//alert(response.id);
// alert('Tema aprobado');
$('#'+i).html("Desaprobar");
$('#'+i).removeClass();
$('#'+i).addClass('desaprobartema text-yellow-500 hover:text-yellow-600 hover:underline mr-3');
$('#p-'+i).html(nupositivo+10);
}
});
});
//desaprobar tema
$('.desaprobartema').click(function(){
var id = $(this).attr('id');
var url = '{{ route("tema.desaprobar") }}';
$.ajax({
type: 'POST',
url: url,
data:
{
"id": id,
"_token": "{{ csrf_token() }}",
},
success: function(response) {
let i=response.id;
let nupositivo= parseInt($('#p-'+i).text(), 10);
//alert(response.id);
// alert('Tema aprobado');
$('#'+i).html("Aprobar");
$('#'+i).removeClass();
$('#'+i).addClass('aprobartema text-yellow-500 hover:text-yellow-600 hover:underline mr-3');
$('#p-'+i).html(nupositivo-10);
}
});
});