Valamas
Valamas

Reputation: 24729

Button with two event functions. How to stop the second during the first function?

I have a "delete" button and on clicking cancel on the confirm box, it still submits the form. What is the best way to stop the form submitting given that these two event functions apply to the same button?

The attribute data-confirm contains the confirm message.

$(document).on('click', "[data-confirm]", 
     (function () { return confirm($(this).attr('data-confirm')); }));
$(document).on("click", "input[type='submit'], button", buttonSubmit);

Here is the function buttonSubmit with custom code ommitted.

var buttonSubmit = (function (e)
{
    e.preventDefault();
    //...
    $(this).closest('form').submit();
});

Given a cancellation of confirm, how can i prevent buttonSubmit code from executing?

Upvotes: 0

Views: 75

Answers (1)

SLaks
SLaks

Reputation: 887365

You're looking for e.stopImmediatePropagation().

Upvotes: 3

Related Questions