Skip to content

Instantly share code, notes, and snippets.

@oliverbenns
Last active December 23, 2015 16:09
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 oliverbenns/6660563 to your computer and use it in GitHub Desktop.
Save oliverbenns/6660563 to your computer and use it in GitHub Desktop.
Clear text on input box click. Restore if no value entered.
// ================================================================================
//
// Clear text on input box on click. Restore if no value entered.
//
// On focus
$('.js-clear').on('focus', function() {
if (this.value === this.getAttribute('value')) {
this.value = "";
}
});
// On unfocus
$('.js-clear').blur(function() {
if (this.value === "") {
this.value = this.getAttribute('value');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment