Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery unbind then bind

I'm unbinding click from these clickable divs and then want to enable clicking again. What I have doesn't work. Any suggestions? Thanks.

    $('#a, #b, #c').on('click', function(e){
        $('#a, #b, #c').unbind('click');
        // some stuff
        // bind again: 
        // this doesn't work: $('#a, #b, #c').bind('click');
    }
like image 560
ialphan Avatar asked Mar 16 '26 01:03

ialphan


1 Answers

You are missing the handler function // this doesn't work: $('#a, #b, #c').bind('click'); when you try to rebind.. what you need is something like below,

$('#a, #b, #c').bind('click', clickHandlerA);

function clickHandlerA() {
   $('#a, #b, #c').unbind('click');
   // some stuff
   // bind again: 
   // this should work: 
   $('#a, #b, #c').bind('click', clickHandlerA);
}
like image 178
Selvakumar Arumugam Avatar answered Mar 18 '26 14:03

Selvakumar Arumugam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!