Skip to content

Instantly share code, notes, and snippets.

@corydeppen
Created August 4, 2010 14:54
Show Gist options
  • Save corydeppen/508253 to your computer and use it in GitHub Desktop.
Save corydeppen/508253 to your computer and use it in GitHub Desktop.
// Select text inside an input field on user click or focus
// http://jquery-howto.blogspot.com/2009/04/select-text-in-input-box-on-user-select.html
$("#myInputField").focus(function(){
// Select input field contents
this.select();
});
// Add this behavior to all text fields
$("input[type=text]").focus(function(){
// Select field contents
this.select();
});
// Selects all text content of textareas if and only if it’s value has changed from the original one
$("textarea").focus(function(){
// Check for the change
if(this.value == this.defaultValue){
this.select();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment