Created
August 16, 2013 20:19
-
-
Save shawnrgrimes/6253194 to your computer and use it in GitHub Desktop.
Form inputs that remember default values.
Example: http://jsfiddle.net/shawnrgrimes/rv8xY/
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
// Inputs that remember value | |
$(':text') | |
.each(function (currentIndex) { | |
$(this).data("originalValue", this.value); | |
}) | |
.focus(function () { | |
$(this).removeClass("unfocused"); | |
if ($(this).val() === $(this).data("originalValue")) { | |
$(this).val(''); | |
} | |
}) | |
.blur(function () { | |
if ($(this).val() === '') { | |
$(this).val($(this).data("originalValue")); | |
$(this).addClass("unfocused"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment