title: Set focus to a button inside bootstrap modal when it opens
body: <p>I am trying to achieve the following:</p>
  
  <ol>
  <li>When the page loads, the focus goes to the first element in the form.</li>
  <li>When the button is pressed on form, a modal appears to confirm and the focus should be on the "Proceed" button inside modal dialog.</li>
  </ol>
  
  <p>I managed to to make the first one work, but for the second I have no idea why it is not working. Following is my code.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form method="post" {% if action %} action="{{ action }}" {% endif %} role="form" enctype="multipart/form-data"&gt;
  &lt;!-- Modal --&gt;
    &lt;div class="modal fade" id="confirmationModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"&gt;
      &lt;div class="modal-dialog" role="document"&gt;
        &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
            &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
              &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
            &lt;/button&gt;
            &lt;h4 class="modal-title" id="myModalLabel"&gt;Confirmation&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
             {{ confirm | default: "Would you like to proceed?" }}
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
            &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
            &lt;button type="submit" id="submit-main-form" class="btn btn-primary"&gt;
                &lt;i class="fa fa-save"&gt;&lt;/i&gt; {{ submit_text | default: "Proceed" }}
            &lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Script</strong></p>
  
  <pre><code>/* Sets focus on the first element of the form */
  $(document).ready(function() {
  
      $('form:first *:input[type!=hidden]:first').focus();
  
      $("#confirmationModal").on('show.bs.modal', function(event) {
          // not setting focus to submit button
          $("#submit-main-form").focus();
      });
  });
  </code></pre>