Skip to content

Instantly share code, notes, and snippets.

@cyberwani
Forked from makeusabrew/label-to-placeholder.js
Created March 25, 2014 15:16
Show Gist options
  • Select an option

  • Save cyberwani/9763943 to your computer and use it in GitHub Desktop.

Select an option

Save cyberwani/9763943 to your computer and use it in GitHub Desktop.

Revisions

  1. @makeusabrew makeusabrew created this gist May 22, 2011.
    8 changes: 8 additions & 0 deletions label-to-placeholder.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    $("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();
    }
    });