I have a table with patient records, each record has a delete button, when the table is loaded normally (With a foreach and the data sent from my controller) the buttons work fine, but, I have an input to search for records with HttpRequest. It does the search well, but when I load the table with JS, all the buttons of the records that I loaded stop working.
@foreach ($pacientes as $paciente)
<tr id="tr-table">
.
.
.
<td><div class="size-delete"><a href="#" id="activeUser" class="showUser activeUser"><i class="far fa-trash"></i> Activar</a></td>
</tr>
@endforeach
When the JS search function returns the records to me, I load them like this.
let addPaciente = `<tr id="tr-table">
<th scope="row">`+paciente.ID+`</th>
<td><div class="size-delete"><a href="#" id="activeUser" class="showUser activeUser"><i class="far fa-trash"></i> Activar</a></td>
</tr>`;
document.getElementById('table-body').innerHTML += addPaciente;
Then each button should call this function. But if I load the table with Js after a search, the buttons don't work. It's like they don't have the Click event
let activeUser = document.querySelectorAll('.activeUser');
activeUser.forEach((element) => {
element.addEventListener('click', function(){
console.log("Hello");
})
})
I do not know what is the problem... tienen e