Skip to content

Instantly share code, notes, and snippets.

@stopsatgreen
Created December 18, 2012 10:09
Show Gist options
  • Save stopsatgreen/4326822 to your computer and use it in GitHub Desktop.
Save stopsatgreen/4326822 to your computer and use it in GitHub Desktop.
Detect placeholder support in the browser and use value if it isn't present.
function hasPlaceHolder() {
return 'placeholder' in document.createElement('input');
}
function html5forms() {
var formPlaceholder = hasPlaceHolder();
if (formPlaceholder === false) {
$('input[type=text]').each(function() {
if($(this).attr('placeholder')) {
var placeholderText = $(this).attr('placeholder');
$(this).attr('value',placeholderText);
}
});
emptyTextBox();
}
}
document.addEventListener('DOMContentReady', html5forms, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment