Created
March 28, 2011 07:49
-
-
Save madhums/890126 to your computer and use it in GitHub Desktop.
Changing the default text value on focus with jQuery
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
$('.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