2

Im having a button to open a popup-windwow. By clicking on itself again, the popup-window should close (this one works). But after closing it is not possible to reopen the window. How can I fix this unbind-Problem?

//loading Popup
//0 means disabled; 1 means enabled;
var popupStatus = 0;
function loadPopup ($elem) {
    //loads popup only if it is disabled
    if(popupStatus==0){  
        $elem.fadeIn(300, function(){
        //Closing popup by clicking the button
            $("#popup-button").bind("click", function(){
                    disablePopup();
            });
        });
        popupStatus = 1;  
    }
}

//disable popup
function disablePopup(){
        //disables popup only if it is enabled  
        if(popupStatus==1){  
            $(".popup-background").fadeOut("slow");  
                    $("#popup-wrapper").fadeOut("slow");

            $("#popup-button").unbind("click", function(){
                    disablePopup();
            });
             popupStatus = 0;  
        }
    }  
Jules
  • 3,105
  • 2
  • 27
  • 33

1 Answers1

2

There is no unbind necessary in my opinion, try something like this:

$('#popup-button').click(function(){
    $('#popup-window').fadeToggle();
});
Christoph Geschwind
  • 2,602
  • 1
  • 13
  • 15