Skip to content

Instantly share code, notes, and snippets.

@jackreichert
Created March 1, 2012 21:50
Show Gist options
  • Save jackreichert/1953471 to your computer and use it in GitHub Desktop.
Save jackreichert/1953471 to your computer and use it in GitHub Desktop.
Polyfill for the Input "Placeholder" Attribute.
function activatePlaceholders() {
var detect = navigator.userAgent.toLowerCase();
if (detect.search("msie") > 0 ) {
$('input[type=text],input[type=email]').each(function(ind,elem) {
if ($(elem).attr('placeholder') != ""){
$(elem).val($(elem).attr("placeholder"));
$(elem).click(function() {
if ($(this).val() == $(this).attr("placeholder")) {
$(this).val("");
}
});
$(elem).blur(function() {
if ($(this).val() == "") {
$(this).val($(this).attr("placeholder"));
}
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment