Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Last active August 29, 2015 13:56
Show Gist options
  • Save ChrisLTD/9061286 to your computer and use it in GitHub Desktop.
Save ChrisLTD/9061286 to your computer and use it in GitHub Desktop.
jQuery & modernizr placeholder text fallback
// placeholder text fallback
if(!Modernizr.input.placeholder){
$('input').not('.placeholder-fallback-inited').each(function() {
var $this = $(this);
$this.val( $this.attr('placeholder') );
$this.addClass('placeholder-fallback-inited');
})
.focus(function(){
var $this = $(this);
if( $this.val() == $this.attr('placeholder') ){
$this.val('');
}
})
.blur(function(){
var $this = $(this);
if( $this.val() == '' ){
$this.val( $this.attr('placeholder') );
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment