简体   繁体   English

jQuery将复选框和标签包装在div中

[英]jquery wrap the checkbox and label in div

i have created one wordpress plugin to create contact form.. if i create multiple checkbox it looks like below code: 我已经创建了一个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>

now i want to wrap each checkbox and it's label to a div for 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>

how to do that? 怎么做?

Try 尝试

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

Demo: Fiddle 演示: 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM