title: Set focus after an alert message in jquery
body: <p>I'm trying to set the focus in a input after an alert box appear. I have problem to set the focus on my field, ref. </p>
  
  <p>My code is simple:</p>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>var toFix = true;
  $( "#add" ).click(function(e) {
      if(toFix){
          if (confirm('Not valid')) $( "#ref" ).focus();
          e.preventDefault();
      }
  });
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;input class="input-text submit" type="submit" id="add" name="submit" value="Add" style="text-align: center"/&gt;    
  &lt;input class="input-text" type="text" name="ref" id="ref"&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong>
  <a href="http://jsfiddle.net/Cu74c/" rel="nofollow">Demo</a></p>