Skip to content

Instantly share code, notes, and snippets.

@papakpmartin
Last active December 12, 2015 12:39
Show Gist options
  • Save papakpmartin/4773555 to your computer and use it in GitHub Desktop.
Save papakpmartin/4773555 to your computer and use it in GitHub Desktop.
My defaultify function using defaultValue and not a data- attribute
/**
* defaultify gets any INPUTs classed with .defaultify and causes them to "empty" onFocus and
* repopulate the default onBlur. This uses the HTML4 built-in `defaultValue` property (see
* https://developer.mozilla.org/en-US/docs/DOM/HTMLInputElement
*
* @returns nothing
* @requires jQuery
* @author KPM
*/
defaultify: function() {
$j('input.defaultify')
.focus( function(){
if ( this.value === this.defaultValue ) {
this.value = '';
}
})
.blur( function(){
if ( this.value === '' ) {
this.value = this.defaultValue;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment