Skip to content

Instantly share code, notes, and snippets.

@amycheng
Created January 29, 2013 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amycheng/4668371 to your computer and use it in GitHub Desktop.
Save amycheng/4668371 to your computer and use it in GitHub Desktop.
polyfill for placeholder
$(function() {
function isPlaceholderSupported() {
var input = document.createElement("input");
return ('placeholder' in input);
}
var placeholdersupport = isPlaceholderSupported();
if (placeholdersupport == false) {
// If there is no placeholder support,
// set the value of the input field to the
// placeholder value
$('#query').val('Search and type enter');
}
$('#query').focus(function() {
if (placeholdersupport == false) {
if ($(this).val() == 'Search and type enter')
$(this).val('');
}
});
$('#query').blur(function() {
if (placeholdersupport == false) {
if($(this).val() == '')
$(this).val('Search and type enter');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment