Do you want to use JavaScript (jQuery) confirmation dialog before deleting some item? It's very simple in jQuery. Just add class "confirmDelete" to your HTML delete link.
E.g.
<a href="/delete.php?postId=15" class="confirmDelete">delete article</a>
Don't forget to link jQuery library:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
And finally the JavaScript (jQuery) function:
$('.confirmDelete').click(function (){ var answer = confirm("Are you sure you want to delete this article?"); return !!answer; });And complet testing HTML page:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Delete confirmation dialog</title> </head> <body> <areticle> <p>Aliquam accumsan lacus sed risus vulputate lacinia. Suspendisse potenti. Ut convallis enim vel erat euismod laoreet. Aenean ornare velit vel imperdiet luctus. Pellentesque condimentum luctus mattis.</p> </areticle> <p><a href="/delete.php?postId=15" class="confirmDelete">delete article</a></p> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript"> $('.confirmDelete').click(function (){ var answer = confirm("Are you sure you want to delete this article?"); return !!answer; }); </script> </body> </html>
Comments
Post a Comment