Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
Created June 14, 2012 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hereswhatidid/2931742 to your computer and use it in GitHub Desktop.
Save hereswhatidid/2931742 to your computer and use it in GitHub Desktop.
Check for and enable HTML5 placeholder attribute
$.support.placeholder = ('placeholder' in document.createElement('input'));
if (!$.support.placeholder) {
$('input[placeholder],email[placeholder]').each(function() {
$(this)
.val($(this).attr('placeholder'))
.on({
'focus': function() {
if ($(this).val() == $(this).attr('placeholder')) $(this).val('');
},
'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