Last active
December 23, 2015 16:09
-
-
Save oliverbenns/6660563 to your computer and use it in GitHub Desktop.
Clear text on input box click. Restore if no value entered.
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
// ================================================================================ | |
// | |
// 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