Skip to content

Instantly share code, notes, and snippets.

@dantoncancella
Created January 18, 2013 12:54
Show Gist options
  • Save dantoncancella/4564382 to your computer and use it in GitHub Desktop.
Save dantoncancella/4564382 to your computer and use it in GitHub Desktop.
jQuery 'plugin' dor defaultvalue of an input
(function($) {
$.fn.defaultValue = function() {
$(this).each(function(i, el) {
var actualValue,
$el = $(this),
defaultValue = el.value;
$el.on('focus', function() {
actualValue = $el.val();
if (actualValue == defaultValue) {
$el.val('');
}
});
$el.on('blur', function() {
actualValue = $el.val();
if (!actualValue) {
$el.val(defaultValue);
}
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment