Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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