$('#dlg').dialog('dialog').attr('tabIndex','-1').bind('keydown',function(e){ if (e.keyCode == 27){ $('#dlg').dialog('close'); }});