Skip to content

Instantly share code, notes, and snippets.

@jwlawrence
Created May 31, 2013 19:14
Show Gist options
  • Save jwlawrence/5687243 to your computer and use it in GitHub Desktop.
Save jwlawrence/5687243 to your computer and use it in GitHub Desktop.
If browser does not support HTML5 placeholder attribute, simulate the effect with jQuery
$('.search-box').each(function(){
if(!Modernizr.input.placeholder){
var $el = $(this),
placeholderText = $el.attr('placeholder');
if( placeholderText ){
$el.addClass('placeholder-text').val(placeholderText)
.bind('focus', function() {
if( $el.val() === placeholderText ) {
$el.val('').removeClass('placeholder-text');
}
}).bind('blur', function() {
if( $el.val() === '' ) {
$el.val(placeholderText).addClass('placeholder-text');
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment