Intercept click event on a button, ask for confirmation, then proceed

Posted by Blankman on Stack Overflow See other posts from Stack Overflow or by Blankman
Published on 2011-01-12T22:57:30Z Indexed on 2011/01/12 23:54 UTC
Read the original article Hit count: 204

Filed under:

Based on a variable SomeCondition, I need to intercept a click event on a button, and ask for confirmation, if they say ok, proceed, otherwise ignore click.

So something like:

if(SomeCondition) {

// disable click on button

var isOk = window.confirm("Are you sure?");

if(isOk) {
        $("#button1").click();
}

}

Note: button1 has already been wired up with a click event via javascript from an external .js file that I can't change.

I don't know what the click event was bound too, so I have to disable the click if SomeCondition is true, then ask for confirmation, then continue with the click.

© Stack Overflow or respective owner

Related posts about jQuery