Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kylerush/8f2717705ee172a3533f to your computer and use it in GitHub Desktop.
Save kylerush/8f2717705ee172a3533f to your computer and use it in GitHub Desktop.
$('form :input').each(function(index, elem) {
var eId = $(elem).attr('id');
var label = null;
if (eId && (label = $(elem).parents('form').find('label[for='+eId+']')).length === 1) {
$(elem).attr('placeholder', $(label).html());
$(label).addClass('hide-label');
}
});
@vickyRuiz
Copy link

Great snippet. I like that it only hides the labels!

@andrewtmiller
Copy link

Works great, but is also pulls in any HTML markup that is in the comment as well.

For example, it pulled in my < span > tag from my required fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment