Reputation: 1261
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');
}
Upvotes: 3
Views: 9956
Reputation: 79850
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);
}
Upvotes: 5
Reputation: 1291
to "unbind" on u need to use ".off" http://api.jquery.com/off/
$('#a, #b, #c').on('click', function(e){
$('#a, #b, #c').off('click');
// some stuff
// bind again:
// this doesn't work: $('#a, #b, #c').bind('click');
}
Upvotes: 1