Skip to content

Instantly share code, notes, and snippets.

@JPKCom
Forked from makeusabrew/label-to-placeholder.js
Created February 22, 2016 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPKCom/1ce7734a1e85101b4da7 to your computer and use it in GitHub Desktop.
Save JPKCom/1ce7734a1e85101b4da7 to your computer and use it in GitHub Desktop.
Simple jQuery snippet to convert form labels into inline placeholders
$("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).remove();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment