Skip to content

Instantly share code, notes, and snippets.

@Demwunz
Created March 14, 2012 16:27
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 Demwunz/2037643 to your computer and use it in GitHub Desktop.
Save Demwunz/2037643 to your computer and use it in GitHub Desktop.
JavaScript: Modernizr & jQuery placeholder replacement
if(!Modernizr.input.placeholder){
$('input[type=text]').each(function(i, elem) {
var input = $(elem),
placeholder = input.attr('placeholder');
if (this.defaultValue === '') {
this.defaultValue = placeholder;
}
input.on('focus', function () {
this.value == this.defaultValue ? this.value = '' : null;
})
.on('blur', function () {
!this.value.length ? this.value = this.defaultValue : null;
}).blur();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment