I'm trying to use sweet alert
to confirm the intention to delete a row from the MySQL table, but I think I'm not sure how to do it.
Using alert
simple I do this:
<a title='Remover linha' class= 'deletrow' href='deletrow.php?id=$id'><i class='fa fa-remove resultsfa5'></i></a>
In the file deletrow.php
is MySQL to delete the line and before deleting the JS asks for confirmation:
$('.deletrow').on('click', function () {
return confirm('Tem certeza que deseja apagar esta linha?');
});
But trying with sweet alert
does not work, because when I put href
inside the <a>
tag (without href
it works) it just flashes on the screen.
In this fiddle you can reproduce the problem. Just remove the href
from within the tag that already works, otherwise it just blinks ... but then how do I point to the file where the query
of MySQL is?
Below is the functional snippet (with button
):
document.querySelector('.sweet-1').onclick = function(){
swal("Nice alert!");
};
<script src="//code.jquery.com/jquery-2.1.1.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://tristanedwards.me/u/SweetAlert/lib/sweet-alert.js"></script><linkhref="http://tristanedwards.me/u/SweetAlert/lib/sweet-alert.css" rel="stylesheet"/>
<div class="row">
<div class="col-sm-2 text-center">
<p><button class="btn btn-primary sweet-1">Abrir alert</button></p>
</div>
</div>
So how can I use with <a href...>
, or even using <button>
where I include the rule to delete the line?