I think there should be a .first() in there as in $('.ui-dialog').find('button').first().trigger('click'); Otherwise you'll trigger the click of all the buttons of the dialog if there are more than one.
Ben Clayton's is the neatest and shortest and it can be placed at the top of your index page before any jquery dialogs have been initialized.
but i can't understand how it's working without the trigger!
probably u have another event bind that do the same It works beautifully with the latest version of JQuery UI (1.8.1).
Once you have the button focus logic down and implemented, then I would probably add a key handler to the dialog itself and have it invoke the action associated with the currently "focused" button.
EDIT: I'm making the assumption that you want to be able hit enter anytime you are filling out form elements and have the "current" button action take precedence.
In the following example, you'll see a simple text entry box which is treated as a j Query UI datepicker.Ordinarily, the "button focus" would start on your default button.Tabbing to a different button would change the "button focus".Also it assumes that there is only one active dialog at any given time which may not be the case. Note: As mentioned above, the button that is pressed on enter is dependent on your setup.So, in some cases you would want to use the :first selector in method and in others you may want to use the :last selector.