Currently I have a delete button on my datatable and I'm using data-id
& class btnDelete
just to get it the id
foreach row.
<button data-id="1" class="btnDelete">Delete</button>
Now I have this jQuery & SweetAlert code
$(".btnDelete").click(function() {
var id = $(this).attr('data-id');
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
alert(id);
}
});
});
But this gives me an error like this
Uncaught (in promise) ReferenceError: id is not defined
BTW: I can alert the var id
outside of the sweetalert but can't alert it inside the code of sweetalert