I have many links in a HTML-table, which delete corresponding row, when clicked (calling a PHP-script via GET parameter).
They all have a class delete_row.
How could I please display a confirm('Really delete?') dialog using jQuery, when such a link is clicked?
And of course prevent following that link when No has been selected in the dialog.
In jQuery if I want to check if the user clicked any link in page I use this code: $('a'). click(function() { // do something });
In the most simple way, you can use the confirm() function in an inline onclick handler.
To check if an element was clicked, add a click event listener to the element, e.g. button. addEventListener('click', function handleClick() {}) . The click event is dispatched every time the element is clicked.
Very simple and effective one line solution without using jquery:
<a href="to/your/path" onclick="return confirm('Are you sure you want to delete?');">Delete</a>
Try this.
$('.delete_row').click(function(){
return confirm("Are you sure you want to delete?");
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With