Skip to content

Instantly share code, notes, and snippets.

@fakiolinho
Last active December 16, 2015 11:59
Show Gist options
  • Save fakiolinho/5431064 to your computer and use it in GitHub Desktop.
Save fakiolinho/5431064 to your computer and use it in GitHub Desktop.
jQuery: IE Placeholder Issue
/* If browser doesn't recognize attr placeholder change inputs value on focus/blur with the placeholder value */
/* Works for jQuery version > 1.9 were $.browser was deprecated and cannot be used anymore */
function iePlaceholder() {
if(document.createElement("input").placeholder == undefined)
{
$(':input').each(function() {
var input = $(this);
$(input).val(input.attr('placeholder'));
$(input).focus(function() {
if (input.val() == input.attr('placeholder'))
{
input.val('');
}
});
$(input).blur(function() {
if (input.val() == '' || input.val() == input.attr('placeholder'))
{
input.val(input.attr('placeholder'));
}
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment