0

I have a confirmation dialog with modal dialog from Bootstrap. I was add "autofocus" attribute for the"Yes" button. But when the dialog show, the button can't set as autofocus. I have try this code:

$('.modal').on('shown', function () {

    $("#btnYes").focus();

});

But also didn't work for me.

If you have any solution, please tell me. Thanks in advance.

Dharmana
  • 99
  • 1
  • 3
  • 11

1 Answers1

2

If you're using Bootstrap 3.0+ try this:

 $('.modal').on('shown.bs.modal', function () {
    $(this).find('[autofocus]').focus();
});

Also check out this post

Community
  • 1
  • 1
Ju66ernaut
  • 2,592
  • 3
  • 23
  • 36