In my HTML display I have a table showing some names of uploaded files. and a button to delete that file.
the names of files are loaded dynamically by Php
<tbody>
<?php
foreach ($uploaded_files as $val) {
?>
<tr>
<th>
<a href="delete_this_file/<?php echo $val['id']; ?>" class="delete" data-confirm="Are you sure to delete this item?"><div class="btn btn-danger">Delete</div></a>
</th>
<th>
<?php echo $val['file_name']; ?>
</th>
</tr>
<?php
}
?>
</tbody>
and I have a javascript function in my html head section like this, to confirm did he really want to delete it.
$(document).ready(function() {
var deleteLink = document.querySelector('.delete');
deleteLink.addEventListener('click', function(event) {
event.preventDefault();
var choice = confirm(this.getAttribute('data-confirm'));
if (choice) {
window.location.href = this.getAttribute('href');
}
});
});
this is working well only for first button only, and for other buttons it is redirecting to this link href="delete_this_file/
can some one show me the error in this code. I can't figure it out.
Thank You very Much