Cover label and input in the same div

I try to wrap my input radioand it labelin one div, but somehow it does not complete the input only. My code is:

HTML:

<div class="payment_processor-section">
    <input id="input_0" class="form-radio" type="radio" checked="checked"  name="payment_processor" value="1">
    <label for="input_0">Credit Card</label>
    <input id="input_1" class="form-radio" type="radio" name="payment_processor" value="0">
    <label for="input_1" style="">I will send payment by check</label>
</div>

Jquery I'm trying to do:

$('.payment_processor-section input').map(function(index){
    $(this, $("label[for='"+this.id+"']") ).wrapAll('<div class="abc">');
});

Please, help.

+4
source share
3 answers

Try the following:

$('.payment_processor-section input').map(function(index){
  $(this).next().andSelf().wrapAll('<div class="abc">');
});

fiddle

+13
source

Or http://jsfiddle.net/43jdq/

$('.payment_processor-section input').map(function(index){
 $(this).add($("label[for='"+this.id+"']")).wrapAll('<div class="abc">');
});
+8
source

javascript jQuery , a in

var collection=$('.payment_processor-section *')
for(var i = 0; i < collection.length; i+=2) {
      collection.slice(i, i+2).wrapAll("<div class='group'></div>");
}
0

Source: https://habr.com/ru/post/1543995/


All Articles