Last active
September 27, 2015 16:48
-
-
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
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
// ------------------------------ | |
// 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