Skip to content

Instantly share code, notes, and snippets.

@jonesch
Created August 13, 2013 21:45
Show Gist options
  • Save jonesch/6226018 to your computer and use it in GitHub Desktop.
Save jonesch/6226018 to your computer and use it in GitHub Desktop.
Simple Placeholder Fallback that is dependent on Modernizer. I am sure there is a cleaner way, but I just wanted to see if I could do it from scratch.
if(!Modernizr.input.placeholder) {
$('[placeholder]').each(function(i){ $(this).val($(this).prop('placeholder')); });
$('[placeholder]').on({
'focus' : function(evt){
if($(this).val() === $(this).prop('placeholder')) { $(this).val(''); }
},
'blur' : function(evt){
if($(this).val() !== $(this).prop('placeholder')) { $(this).val($(this).prop('placeholder')); }
}
});
$('.block-internal-form').submit(function(){
$('[placeholder]').each(function(i){
if($(this).val() === $(this).prop('placeholder')) { $(this).val(''); }
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment