Itai Sagi
Itai Sagi

Reputation: 5615

Adding event handlers on object creation doesn't work?

I have the following:

MycheckModal.__construct = function(element){
this.blackout = $("<div class='modal-backdrop'></div>")
    .attr("style", 'left:0px;top:0px;position:absolute;background:black')
    .css("opacity", "0.5")
    .css("height", $(document).height() + 'px')
    .css("width", $(document).width() + 'px')
    .css("z-index", "5000");

this.blackout.live("click", function(){
    MycheckModal.__destruct();
});

}

MycheckModal.__destruct = function(){
    this.element = null;
    this.url = null;
    this.blackout.fadeOut(150, function(){ 
        MycheckModal.blackout.remove();
        MycheckModal.blackout = null;
        } );
    this.modal.fadeOut(150, function(){ 
        MycheckModal.modal.remove();
        MycheckModal.modal = null;
        } );    
}

it's a bit larger code, but you get the jist. anyway - the event handler isn't registering, however - when I register it explicitly - outside the constructor - it works fine.

Any ideas what I need to do?

Upvotes: 1

Views: 89

Answers (2)

thecodeparadox
thecodeparadox

Reputation: 87073

this.blackout.on("click", function(){
    MycheckModal.__destruct();
});

Upvotes: 1

McGarnagle
McGarnagle

Reputation: 102763

I'm not sure why, but try using "click" instead of "live".

this.blackout.click(function() {
    MycheckModal.__destruct();
});

Upvotes: 1

Related Questions