Created
September 10, 2014 18:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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