Skip to content

Instantly share code, notes, and snippets.

@timnovinger
Last active September 27, 2015 16:48
Show Gist options
  • Save timnovinger/1002f2587902c7562a8e to your computer and use it in GitHub Desktop.
Save timnovinger/1002f2587902c7562a8e to your computer and use it in GitHub Desktop.
ColorJar: Add HTML5 input placeholder support to older browsers only when HTML5 not supported
// ------------------------------
// Form Input Placeholder
// ------------------------------
if (!Modernizr.input.placeholder)
{
$('input[placeholder], textarea[placeholder]').each(function(i, input){
var $input = $(input);
// Initially load the placeholder value
if ($input.val() === '') { $input.val($input.attr('placeholder')); }
$input
.bind('focusin', function(){
var $this = $(this);
if ($this.val() == $input.attr('placeholder')) { $this.val(''); }
})
.bind('focusout', function(){
var $this = $(this);
if ($this.val() === '') { $this.val($input.attr('placeholder')); }
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment