jquery包装div中的复选框和标签

时间:2013-11-13 10:03:46

标签: javascript jquery

我创建了一个wordpress插件来创建联系表单..如果我创建多个复选框,它看起来像下面的代码:

<input class="newch" name="chkbox[]" value="Product Specifcation" type="checkbox">
 Product Specifcation<br>

 <input class="newch" name="chkbox[]" value="Country Of origin" type="checkbox">
 Country Of origin<br>

 <input class="newch" name="chkbox[]" value="Minimum Order quantity" type="checkbox">
 Minimum Order quantity<br>

 <input class="newch" name="chkbox[]" value="Prouduct Warranty" type="checkbox">
 Prouduct Warranty<br>

 <input class="newch" name="chkbox[]" value="Unit Price" type="checkbox">
  Unit Price<br>

现在我想将每个复选框及其标签包装到 ex

的div中
  <div class="chk-bx">
 <input class="newch" name="chkbox[]" value="Unit Price" type="checkbox">
  Unit Price<br>
  </div>


  <div class="chk-bx">
 <input class="newch" name="chkbox[]" value="Prouduct Warranty" type="checkbox">
 Prouduct Warranty<br>
  </div>


 <div class="chk-bx">
 <input class="newch" name="chkbox[]" value="Country Of origin" type="checkbox">
 Country Of origin<br>

  </div>

怎么做?

1 个答案:

答案 0 :(得分:1)

尝试

$('.newch').each(function () {
    var $this = $(this);
    $this.add(this.nextSibling).add($this.next()).wrapAll('<div class="chk-bx"/>')
})

演示:Fiddle