I looking for to enable a function (and not the event) after a click function and disable the same function after another click function, for exemple :
function foo () {
$('#bg').hover(function() {
$(this).css('background','red');
}, function(event) {
$(this).css('background','green');
});
$('#button').click(function(){
if (!$(#button).hasClass('active')) {
foo(); // enable foo
} else {
??? // I would like to disable foo()
}
});
I tried to use bind / unbind & on / off function, but I think I understand it reserved to the event (the click function) and not the callback function.
I can obviously write a second function for disable the action of foo()
but I would like to know if there is a way to achieve this with optimization.