In a jquery modal dialog, is there a way to select a button as the default action (action to execute when the user presses enter)?
Example of jquery web site: jquery dialog modal message
In the example above the dialog closes when the user presses Esc. I would like the "Ok" button action to be called when the user presses Enter.
This worked for me within the dialog using jquery 1.10.2
more options...
You should to use :tabbable selector and index of your button (0 is [X] button, yours started from 1)
try this way:
I'm using version 1.10.0. I could not get it to work with open but with focus. This focuses the second button:
I like this one (it is working for me), which leaves the focus where I wanted to be (a text box)
However, this is working just for one button (Ok button), if needed ':eq(n)' could be set to select other button.
Note: I added a new line returning false to prevent event bubbling when the enter key is handled, I hope it helps better than before.
This simple piece of code styles your buttons and sets the default to the last one: