Created
May 26, 2014 10:02
-
-
Save Kcko/7919b8a6253431611e10 to your computer and use it in GitHub Desktop.
Toogle input value -- better than placeholder (browser support)
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
$.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