Created
May 31, 2013 19:14
-
-
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
This file contains hidden or 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
$('.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