customized my alert - Make the ESC key nonfunctional after use.

customized my alert - Make the ESC key nonfunctional after use.

Hello,

I customized my alert but I have a little problem with the functioning. I want to use the ESC and ENTER key to close the alert. It is functional, the problem is if I press ESC / ENTER the alert will close it if I re-press the ESC opens it again. I would close only once the alert, the ESC / ENTER key is no longer functional. I try to include the function unbind or off and nothing gives the result expected.

I show you my code and if you see what I did wrong please sign made ​​me!




  1. var t = $('#PopAlert');                 

    if(content.length) $('div#Content', t).html(content);                 

    Pop(t, function() {                                   

    $('.x',t).off('click').on('click',function(e) {
      e.preventDefault();
      showPop(t);
      return false;
    });



    $('.ok',t).off('click').click(function (e) {                     
      e.preventDefault();                 
      showPop(t);                 
       if(typeof cb == 'function'){ cb.call(this); }    
      return false ;             
    });                         




    $(document).keypress(function(e) {             
      if(e.keyCode==13) { $('.ok', t).trigger('click'); }                
      if(e.keyCode==27) { $('.x', t).trigger('click'); }         
    });
    });             
    };