Skip to content

Instantly share code, notes, and snippets.

@nessthehero
Created July 16, 2013 17:28
Show Gist options
  • Save nessthehero/6010766 to your computer and use it in GitHub Desktop.
Save nessthehero/6010766 to your computer and use it in GitHub Desktop.
Placeholder polyfill
function ph() {
$("input[placeholder]:not(.ph), textarea[placeholder]:not(.ph)").each(function () {
var place = $(this).attr('placeholder');
$(this).attr('value', place);
$(this).bind('focus', function () {
if ($.trim($(this).attr('value')) == place) {
$(this).attr('value', "");
}
});
$(this).bind('blur', function () {
if ($.trim($(this).attr('value')) == '') {
$(this).attr('value', place);
}
});
$(this).addClass('ph');
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment