jquery UI dialog multiple instances when pressed enter
===

There are similar questions but they could not help me solve this.

When the dialog opens and I press enter, I want this to be equivalent to closing the dialog.

I have written the following but it does not work. Instead, at every ENTER, the focus stays on the element that triggers the opening of the dialog, giving rise to multiple instances.

Thanks

        	var $dialogError = $('<div id="dialogError"></div>').html(vGraph.getLastErrorMsg()).dialog({
    						autoOpen: false,
    						open: function() {  
    							$("#dialogError").keydown(function(e) {
    									alert("enter");
    									if (e.keyCode == $.ui.keyCode.ENTER) {
    										$(this).dialog("close"); 
    
    									}
    							});
    			
    						},
    						title: 'Error'
    				});
    
    $dialogError.dialog('open');
				


 