Skip to content

Instantly share code, notes, and snippets.

@dziudek
Created June 11, 2013 12:54
Show Gist options
  • Save dziudek/5756567 to your computer and use it in GitHub Desktop.
Save dziudek/5756567 to your computer and use it in GitHub Desktop.
jQuery placeholder polyfill
jQuery(document).ready(function() {
jQuery('*[placeholder]').each(function(i, el) {
el = jQuery(el);
if(el.val() === '') {
el.val(el.attr('placeholder'));
}
el.focus(function() {
if(el.val() == el.attr('placeholder')) {
el.val('');
}
});
el.blur(function() {
if(el.val() === '') {
el.val(el.attr('placeholder'));
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment