Skip to content

Instantly share code, notes, and snippets.

@nessthehero
Created April 9, 2013 17:13
Show Gist options
  • Save nessthehero/5347505 to your computer and use it in GitHub Desktop.
Save nessthehero/5347505 to your computer and use it in GitHub Desktop.
Simple placeholder polyfill
// Requires Modernizr
if (!Modernizr.input.placeholder) { ph(); }
function ph() {
$("input[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