Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created June 26, 2009 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/136687 to your computer and use it in GitHub Desktop.
Save tpitale/136687 to your computer and use it in GitHub Desktop.
jQuery clear on focus
;(function($) {
$.fn.clearfocus = function() {
return this.each(function() {
var $field = $(this);
var original_value = $field.val();
$field.focus(function() {
if($field.val() == original_value) $field.val("");
});
$field.blur(function() {
if($field.val() == "") $field.val(original_value);
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment