Santhucool
Santhucool

Reputation: 1706

Focus modal button not working

I have a modal and in that modal some content and a button. I want to focus on that button on loading modal.

Check my fiddle: FIDDLE

What I did is I give $("#closebtn").focus(); for focusing the button on load. This will help user to simply enter on keyboard without using mouse.

But not working.please guide me to do the same, is it any way that foxus can be embedded in html or css itself?

Upvotes: 1

Views: 202

Answers (1)

tmg
tmg

Reputation: 20383

You can not just $("#closebtn").focus(); You need to do it when modal is shown. The event for that is shown.bs.modal. Like this Fiddle

$('#myModal1').on('shown.bs.modal', function () {
  $("#closebtn").focus();
});

Upvotes: 2

Related Questions