Created
March 14, 2012 16:27
-
-
Save Demwunz/2037643 to your computer and use it in GitHub Desktop.
JavaScript: Modernizr & jQuery placeholder replacement
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
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