I need help with binding back after I unbind an element. Basically, I have three anchor elements, and I want to achieve this:
When one of them is clicked, the other two can’t be clicked. Then when the user clicks the close button, I want to bind back the click event for all three links.
To unbind is not a problem, but the binding back is not working. I didn’t post any code because I think that the solution provided will work in general, not just in my case.
Is there maybe any other way to achieve what I want, but not with the use of bind/unbind or on/off?
Edit:
Here is how i have done it.The animated div is called miniContainer.This is the sample for one anchor, but it is the same thing for all three.
//First Link
krug1Link.click(function(element){
if(miniContainer.hasClass('animirano')){
return false;
};
element.preventDefault();
miniContainer.stop().animate({ height:360 },{duration:500,easing: 'easeOutBack'});
miniTekst1.animate({opacity:'1'},1200);
polaroidMali.animate({opacity:'1'},1200);
miniContainer.addClass('animirano');
});
//Close Mini Container
close.click(function(element){
miniTekst1.animate({opacity:'0'},1200);
miniTekst2.animate({opacity:'0'},1200);
polaroidMali.animate({opacity:'0'},1200);
polaroidMali2.animate({opacity:'0'},1200);
miniContainer.animate({marginTop: 10, height:1},{duration:600,easing: 'easeInBack'});
miniContainer.removeClass('animirano');
});
Don’t
bindandunbindto do this.Choose a common ancestor, and use jQuery’s selector based event delegation.
Then to reenable them all, just add the class back in.
If you’re using jQuery 1.7 or later, then use
.on()instead since it has event delegation built in.Here’s one of the solutions from the comments below.
demo: http://jsfiddle.net/c9Ydy/3/
js
css