Could someone tell me how you can deactivate the event onchange and reactivate it
$(':checkbox').each(function (k, v) {
$(this).onchange = null;//
$(this).off() // works but I do not know how to reactivate onchange event
})
Edit 1: Let me explain you my problem ... I'm using bootstrap toggle onmy checkbox. But maybe this is only a detail.
SO my problem is .. I have a "reset" button on my form. When I click on it, I have a function who loops on each checkbox of my form trying to "reset" each checkbox. By reseting my checkbox I mean setting them to their initial value. . . but doing so I trigger an "onchange" function present later in my code. And I do not want to trigger that "onchange" function
I would recommend one of two options.
First, you can unbind and rebind the handlers by giving the function a name:
function handleCheckboxClick(e) {
//...
}
$(':checkbox').off('change');
$(':checkbox').on('change', handleCheckboxClick);
The other option is to create a variable that you set to true
or false
as needed to specify whether to execute the handler:
$(':checkbox').on('change', function(e) {
if (!window.shouldExecuteCheckboxChangeHandler)
return;
//...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With