Skip to content

Instantly share code, notes, and snippets.

@madhums
Created March 28, 2011 07:49
Show Gist options
  • Save madhums/890126 to your computer and use it in GitHub Desktop.
Save madhums/890126 to your computer and use it in GitHub Desktop.
Changing the default text value on focus with jQuery
$('.default-value').each(function() { // '.default-value' is the class for your fields having default values
var default_value = this.value;
$(this).css('color', '#999'); // this could be in the style sheet instead
$(this).focus(function() {
if(this.value == default_value) {
this.value = '';
$(this).css('color', '#333');
}
});
$(this).blur(function() {
if(this.value == '') {
$(this).css('color', '#999');
this.value = default_value;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment