I have such problem - I need to autofocus some element inside twitter bootstrap modal (after it shows). The tricky part is here - content of this modal is loaded using \'dat
You have an input with the autofocus
attribute you want focused when the bootstrap modal is shown.
Is your modal markup available when JavaScript is loaded?
Register an event handler on all .modal
elements for the shown.bs.modal
event
$('.modal').on('shown.bs.modal', function() {
$(this).find('[autofocus]').focus();
});
Is your modal markup dynamically generated?
Register an event handler on the entire document for the shown.bs.modal
event.
$(document).on('shown.bs.modal', '.modal', function () {
$(this).find('[autofocus]').focus();
});