Last active
December 16, 2015 11:59
-
-
Save fakiolinho/5431064 to your computer and use it in GitHub Desktop.
jQuery: IE Placeholder Issue
This file contains hidden or 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
/* 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