Created
March 1, 2012 21:50
-
-
Save jackreichert/1953471 to your computer and use it in GitHub Desktop.
Polyfill for the Input "Placeholder" Attribute.
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
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