Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created May 26, 2014 10:02
Show Gist options
  • Save Kcko/7919b8a6253431611e10 to your computer and use it in GitHub Desktop.
Save Kcko/7919b8a6253431611e10 to your computer and use it in GitHub Desktop.
Toogle input value -- better than placeholder (browser support)
$.fn.toggleInputValue = function(){
return $(this).each(function(){
var input = $(this);
var defaultValue = input.val();
input.focus(function() {
if(input.val() == defaultValue) input.val("");
}).blur(function(){
if(input.val().length == 0) input.val(defaultValue);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment