title: .focus() not working while inside .on('click', function(event)
body: <p>I'm using the following function to scroll the page to a specific element when a link is clicked, which works just fine:</p>
  
  <pre><code>$('a.scroll-link').on('click', function(event) {
      var target = $(this).attr('href')
      if (target.length) {               
          event.preventDefault();               
          $('html, body').animate({
              scrollTop: $(target).offset().top
          }, 800);
  
      }
  });
  </code></pre>
  
  <p>I'm trying to add a focus() event to focus on an entire form element. It's not working and I can't figure out why. I have tried several variations of the following code:</p>
  
  <pre><code>$('a.scroll-link').on('click', function(event) {
      var target = $(this).attr('href')
      if (target.length) {               
          event.preventDefault();
          $('#mainForm').focus();
          $('html, body').animate({
              scrollTop: $(target).offset().top
          }, 800);
  
      }
  });
  </code></pre>
  
  <p>Variation #2:</p>
  
  <pre><code>$('a.scroll-link').on('click', function(event) {
      $('#mainForm').focus();
      var target = $(this).attr('href')
      if (target.length) {               
          event.preventDefault();
          $('html, body').animate({
              scrollTop: $(target).offset().top
          }, 800);
  
      }
  });
  </code></pre>
  
  <p>Variation #3 with timeout:</p>
  
  <pre><code>$('a.scroll-link').on('click', function(event) {
      var target = $(this).attr('href')
      if (target.length) {               
          event.preventDefault();
          $('html, body').animate({
              scrollTop: $(target).offset().top
          }, 800);
          setTimeout(function() { $('#mainForm').focus() }, 3000);
      }
  });
  </code></pre>
  
  <p>None of them work. FYI, I changed the focus() to an addClass() function, and that works just fine. But focus is much preferred because it disappears when an individual input is selected. I'd rather not have to write another function to remove the class when an input is focused. Much thanks.</p>