I have a table generated in while on PHP, There's a delete button that shows Sweetalert to confirm and redirect to PHP. All is working fine, But the last row in table Sweetalert is not showing up.
Here's the code inside while for this button (Not finished yet, just testing):
<script>
$('.delmod').click(function(e) {
e.preventDefault();
swal({
title: 'Jesteś pewien że chcesz usunąć moduł?',
text: 'Jeżeli są strony przypisane do tego modułu, nie będzie możliwe go usunąć',
type: 'warning',
buttonsStyling: false,
confirmButtonClass: 'btn btn-primary',
cancelButtonClass: 'btn btn-light',
showCancelButton: true,
confirmButtonText: 'Tak, usuń',
cancelButtonText: "Nie"
});
});
</script>
<a href="includes/deleteModule.php?id=<?=$mod['id'];?>" class="delmod"><i class="icon-cross2"></i></a>
I have all rows and the button on right side, Sweetalert is called when clicked and this is working fine. But the last record on the table is not working, I tried with other tables, With different records count, Even if I have 2 rows the first one is working and second (last) is not. Sorry for my English and thank for you help (I'm noobie)
The reason for this not working is, that you set the last $('.delmod').click
eventhandler before the html is rendered by the browser - so it's ignored.
To make this work you'd need to put the javascript after the html.
BUT you shouldn't have this script inside the loop, printed several times. Move it to after the loop.