Skip to content

Instantly share code, notes, and snippets.

@ProxiBlue
Forked from kylerush/label-to-placeholder.js
Last active August 24, 2018 02:33
Show Gist options
  • Save ProxiBlue/e48236c890145eb29843245f3226e184 to your computer and use it in GitHub Desktop.
Save ProxiBlue/e48236c890145eb29843245f3226e184 to your computer and use it in GitHub Desktop.
$('form input:text').each(function(index, elem) {
var eId = $(elem).attr('id');
var label = null;
if (eId && (label = $(elem).parents('form').find('label[for='+eId.replace(':', '\\:')+']')).length === 1) {
$(elem).attr('placeholder', $(label).html().replace(/<\/?[^>]+(>|$)/g, ""));
$(label).addClass('hide-label');
}
});
@ProxiBlue
Copy link
Author

ProxiBlue commented Aug 24, 2018

Adjust to only find text fields, and to escpae fields that contain ':' in field name (example Magento has billing:firstname)
Also strips any HTML from label (spans that designate * (required))

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