Skip to content

Instantly share code, notes, and snippets.

@gpassarelli
Created March 20, 2012 12:49
Show Gist options
  • Save gpassarelli/2134970 to your computer and use it in GitHub Desktop.
Save gpassarelli/2134970 to your computer and use it in GitHub Desktop.
jQuery: Inputs That Remember Original Value
var origValue = [];
$('input.remember').each ( function (currentIndex)
{
origValue.push ( $(this).val () );
$(this).focus ( function ()
{
$(this).removeClass("unfocused");
var defaultText = $(this).val();
if ( $(this).val () == origValue [ currentIndex ] )
{
$(this).val('');
}
$(this).blur(function()
{
var userInput = $(this).val();
if (userInput == '')
{
$(this).val(defaultText);
$(this).addClass("unfocused");
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment