Skip to content

Instantly share code, notes, and snippets.

@cjwd-snippets
Created November 14, 2012 20:00
Show Gist options
  • Save cjwd-snippets/4074407 to your computer and use it in GitHub Desktop.
Save cjwd-snippets/4074407 to your computer and use it in GitHub Desktop.
jQuery: Enable placeholder attribute in old browsers
$(function(){
var d = "placeholder" in document.createElement("input");
if (!d){
$("input[placeholder]").each(function(){
$(this).val(element.attr("placeholder")).addClass('placeholder');
}).bind('focus',function(){
if ($(this).val() == element.attr('placeholder')){
$(this).val('').removeClass('placeholder');
}
}).bind('blur',function(){
if ($(this).val() == ''){
$(this).val(element.attr("placeholder")).addClass('placeholder');
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment