Created
January 29, 2013 22:03
-
-
Save amycheng/4668371 to your computer and use it in GitHub Desktop.
polyfill for placeholder
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
$(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