How can i disable and enable a on click event.
I tried with:
$('#web').on('click', function web_function(event){
event.stopPropagation();
// execute a bunch of action to preform
});
$('#web').off('click'); // click is succesfully removed
$('#web').on('click'); // doesnt work, i need to redefine the actions to perform
Also I tried disabling with:
$('#web').unbind('click'); // click is succesfully removed
$('#web').bind('click'); // nok
But this also doesnt work…
So, i would like to disable/enable the click event without the need to redefine the actions to perform. Some sort of toggle… (click on/off)
And how do i implement the event to stop propagation?
How can i do this?
You need to pass the handler function as the argument whenever you
bind(orrebind).In your case, you can name the function which you can use to pass it any time you re-bind again.. see below,