Skip to content

Instantly share code, notes, and snippets.

@giuliandrimba
Created March 15, 2012 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuliandrimba/2044566 to your computer and use it in GitHub Desktop.
Save giuliandrimba/2044566 to your computer and use it in GitHub Desktop.
IE jQuery Placeholder
$(document).ready(function(){
try {
jsToggle();
} catch (jsToggleE){
}
});
function jsToggle()
{
if(!supports_input_placeholder())
{
$("input, textarea").focus(function()
{
if($(this).val() == $(this).attr("placeholder"))
{
$(this).attr("value","");
$(this).css('color','');
}
}).blur(function(){
if($(this).val() == ""){
$(this).attr("value",$(this).attr("placeholder"));
$(this).css('color','#c3c3c3');
}
});
$("input, textarea").each(function(){
if($(this).val() == ""){
$(this).val($(this).attr("placeholder"));
$(this).css('color','#c3c3c3');
}
});
}
}
function supports_input_placeholder() {
var i = document.createElement('input');
return 'placeholder' in i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment