Say I have this HTML ...
<button class="btn-remove-this">Remove this</button> <button class="btn-remove-that">Remove that</button> <button class="btn-remove-some-other-thing">Remove some other thing</button>
... and this javascript.
$(function() { $('.btn-remove-this').click(function() { functionWhichRemovesThis(); } $('.btn-remove-that').click(function() { functionWhichRemovesThat(); } $('.btn-remove-some-other-thing').click(function() { functionWhichRemovesSomeOtherThing(); }
Now I would like to ask the user for a confirmation dialog before deleting all these things. Is there a way to do this without adding and calling confirm inside each click handler?
I have in mind something like adding one class to all the different buttons (say btn-remove ) and then adding one click handler, which might look like this:
$('.btn-remove').click(function() { if (confirm('Are you sure you want to remove this?')) {
source share