/ Published in: jQuery
This function loops through a result set of inputs and for each result, takes the value of any associated label, applies it as the value of the result, and hides the label. Assumes that any label with the class "error" is not counted (I use labels with the error class for errors...).
Expand |
Embed | Plain Text
$.fn.labelHide = function(){ return this.each(function(){ var current = $(this); var id = current.attr("id"); var label = $("label[for='"+id+"']:not(.error)"); if (id.length && label.length) { current.val(label.text()); label.hide(); } }); }; // Usage: $('input.label-hide').labelHide();
You need to login to post a comment.
