Skip to content

Instantly share code, notes, and snippets.

@llkats
Created June 28, 2012 00:40
Show Gist options
  • Save llkats/3007909 to your computer and use it in GitHub Desktop.
Save llkats/3007909 to your computer and use it in GitHub Desktop.
emulate placeholders in IE9 and other dumb browsers
// test to see if the browser supports native html5 placeholders
jQuery.support.placeholder = (function(){
var i = document.createElement('input');
return 'placeholder' in i;
})();
// if the browser doesn't support placeholders (IE9!!!!!!), do them manually
if (!$.support.placeholder) {
$("input").each(function(){
var current = $(this);
if (current.val() === "" && current.attr("placeholder") !== "") {
current.val(current.attr("placeholder"));
current.focus(function() {
if(current.val() === $(this).attr("placeholder")) {
$(this).val("");
}
});
$(this).blur(function() {
if($(this).val() === "") {
$(this).val($(this).attr("placeholder"));
}
});
}
});
}
/*
* via
* http://stackoverflow.com/questions/8263891/simple-way-to-check-if-placeholder-is-supported
* http://kamikazemusic.com/quick-tips/jquery-html5-placeholder-fix/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment