Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.