Created
March 15, 2012 14:46
-
-
Save giuliandrimba/2044566 to your computer and use it in GitHub Desktop.
IE jQuery Placeholder
This file contains 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
$(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