0

I try to apply a demo modal shown in url:

http://getbootstrap.com/javascript/
after "Varying modal content based on trigger button".

And also use a html code

<input name="email" type="email" id="email" />

...and javascript code

$('#exampleModal').on('show.bs.modal', function (event) {
  var button = $(event.relatedTarget)
  var modal = $(this)
  modal.find('.modal-title').text('Log In')
  modal.find('.modal-body input').val("This Body..")
  $(this).find('#email').focus();//why it doesn't work????????
})

How to set the focus function in email-input automatically? Thank you

1
  • You should use shown.bs.modal event instead of show.bs.modal please check my answer below. Commented Oct 31, 2015 at 7:55

1 Answer 1

1

use shown.bs.modal instead of show.bs.modal

Try something like below:

$('#exampleModal').on('shown.bs.modal', function (event) {
  var button = $(event.relatedTarget)
  var modal = $(this)
  modal.find('.modal-title').text('Log In')
  modal.find('.modal-body input').val("This Body..")
  $(this).find('#email').focus(); //now it will work
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.