Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Created September 10, 2014 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/c9e80a4f1ae216bbd254 to your computer and use it in GitHub Desktop.
Save JamoCA/c9e80a4f1ae216bbd254 to your computer and use it in GitHub Desktop.
Select all text in field upon focus. Chrome's mouseup event prevents select() from working without this hack.
$(function(){
/* Select all text in field upon focus.
Chrome's mouseup event prevents select() from working without this hack.
Add "selectAll" class to input fields or modify to work with any input field */
$('body').on('focus', 'input:text.selectAll', function(){
$(this).one('mouseup', function(e){
e.preventDefault();
}).select();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment