tonelm54
asked on
jQuery wrap-around and append
Im trying to wrap an element in a div, but also add an element in, what Ive tried to do it:-
The element Im trying to wrap around:-
And what Im trying to do it make it so its like
I need to do it all in one line, as I want to put it in a plugin, so it will wrap around and append for each element.
My final solution needs to be in a plugin, so something like:-
Any ideas?
$("#txtLabel1").wrapAll("<div class='divBox'></div>").prepend("<label for='txtLabel1'>ergerg</label>");
The element Im trying to wrap around:-
<input type="text" id="txtLabel1" />
And what Im trying to do it make it so its like
<div class='divBox'>
<input type="text" id="txtLabel1" />
<label for='txtLabel1'>Label Text</label>
</div>
I need to do it all in one line, as I want to put it in a plugin, so it will wrap around and append for each element.
My final solution needs to be in a plugin, so something like:-
$.fn.labelSize = function(options ) {
var settings = $.extend({
// These are the defaults.
}, options );
return this.each(function() {
var thisElement = $(this).clone();
var thisWatermark = $(this).attr("placeholder");
var thisID = $(this).attr("id");
$(this).replaceWith("<div class='tc-LabelSize'>" + thisElement + "<label for='" + thisID +"'>'" + thisWatermark +"'</label></div>" );
});
};
$(".labelSize").labelSize();
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.