I have a jquery dialog and I need to execute some_code () when I press Esc, or click the cancel button. Using the cancel button, you can easily add a function to the cancel button.
$( '#mydialog' ).dialog({ closeOnEscape: true, close: function( event, ui ) { //some_code(); $(this ).dialog( 'destroy' ) }, buttons: { "OK" : function() { $( this ).dialog( "close" ); }, "Cancel" : function() { some_code(); $( this ).dialog( "close" ); } } });
But how can I execute some_code () after pressing ESC? This function should not be called clicking OK, so I canโt just put it in a close event.
source share