Created
June 14, 2012 17:50
-
-
Save hereswhatidid/2931742 to your computer and use it in GitHub Desktop.
Check for and enable HTML5 placeholder attribute
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
$.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