Skip to content

Instantly share code, notes, and snippets.

@jordanharper
Created May 25, 2011 15:47
Show Gist options
  • Save jordanharper/991217 to your computer and use it in GitHub Desktop.
Save jordanharper/991217 to your computer and use it in GitHub Desktop.
Activate <input> placeholder attributes for non webkit browsers
$('input[placeholder]').each(function(){
$(this).focus(function(){
if ($(this).val()==$(this).attr('placeholder')) $(this).val('');
}).blur(function(){
if ($(this).val()=='') $(this).val($(this).attr('placeholder'));
});
});
Or, using modernizer:
if(!Modernizr.input.placeholder){
$("input").each(function(){
if($(this).val()=="" && $(this).attr("placeholder")!=""){
$(this).val($(this).attr("placeholder"));
$(this).focus(function(){
if($(this).val()==$(this).attr("placeholder")) $(this).val("");
});
$(this).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