Created
June 16, 2014 21:26
-
-
Save alkrauss48/d2c2c642e94852cf0f87 to your computer and use it in GitHub Desktop.
Gives your form fields placeholder support for IE8
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
/* Fake placeholder support in browsers that do not support the HTML input placeholder attribute. Ideally this would be paired with a javascript function that prevents form submit if the a given input's value is equivalent to the placeholder attribute. */ | |
/* Requires both jQuery and Modernizr */ | |
function initPlaceholderSupport() { | |
if( ! Modernizr.input.placeholder ) { | |
$('[placeholder]').focus(function() { | |
var input = $(this); | |
if (input.val() == input.attr('placeholder')) { | |
input.val(''); | |
input.removeClass('placeholder'); | |
} | |
}).blur(function() { | |
var input = $(this); | |
if (input.val() == '' || input.val() == input.attr('placeholder')) { | |
input.addClass('placeholder'); | |
input.val(input.attr('placeholder')); | |
} | |
}).blur(); | |
} | |
} | |
initPlaceholderSupport(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment