Skip to content

Instantly share code, notes, and snippets.

@dfadler
Created December 7, 2011 16:51
Show Gist options
  • Save dfadler/1443556 to your computer and use it in GitHub Desktop.
Save dfadler/1443556 to your computer and use it in GitHub Desktop.
Saves default text input value, removes on click, and resets if the user does not enter a string
$('input[type=text]').each(function(i){
var defaultValue = new Array();
defaultValue[i] = $(this).val();
$(this).click(function(){
if($(this).val() == defaultValue[i]){
$(this).val('');
}
});
$(this).focusout(function(){
if($(this).val() == ''){
$(this).val(defaultValue[i]);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment