Skip to content

Instantly share code, notes, and snippets.

@jstarrdewar
Created February 8, 2012 20:13
Show Gist options
  • Save jstarrdewar/1772965 to your computer and use it in GitHub Desktop.
Save jstarrdewar/1772965 to your computer and use it in GitHub Desktop.
Event handler for jQuery.focus() that avoids sudden deselection in browsers like Safari
<!-- simple HTML to test focus handler with -->
<input id="example" type="text" value="Select Me"/>
$("#example").focus(function() {
var input = this;
setTimeout(function() { input.select() }, 0);
});
@jstarrdewar
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment