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.
I could not get any of the answers above to work using jquery 1.9.1
here is what worked for a previously set click
event
var elem = $('#button1');
var oldClick = $._data(elem[0], 'events').click[0].handler;
elem.off('click');
// Pass the original event object.
elem.click(function(e){
if(window.confirm("Are You Sure?")){
oldClick(e);
} else {
return false;
}
});
very similar to Jason Benson's answer above