簡體   English   中英

append如何將一個div變成標簽

[英]How to append a div into labels

小提琴鏈接

如何將 append 一個 div 放入標簽中。 在每個無線電組及其包裝器 div 中。

我有一個動態生成的單選按鈕組代碼,所以我無法使用 HTML 將 static 幫助文本添加到標簽中。

我將 div 放在無線電組 div 下,並添加帶有幫助文本的 div,並用另一個 div 包裝每個無線電組,然后使用 append。 我正在使用類將其唯一的幫助文本 div 添加到其標簽中。

在屏幕之前

后屏幕



<div class="helperTextWrapper" >

<div class="radioTable">
 <div>
    <span>
       <label class="RadioButtonHelperText1">Yes</label>
   </span>
</div>
 <div>
    <span>
       <label class="RadioButtonHelperText2">No</label>
   </span>
</div>
</div>

<div class="RadioButtonHelperTextLabel1">Yes helper text</div>
<div class="RadioButtonHelperTextLabel2">no helper text</div>

</div>

<div class="helperTextWrapper" >

<div class="radioTable">
 <div>
    <span>
       <label class="RadioButtonHelperText1">Yes</label>
   </span>
</div>
 <div>
    <span>
       <label class="RadioButtonHelperText2">No</label>
   </span>
</div>
    <div>
    <span>
       <label class="RadioButtonHelperText3">Not sure</label>
   </span>
</div>
</div>

<div class="RadioButtonHelperTextLabel1">Yes helper text</div>
<div class="RadioButtonHelperTextLabel2">no helper text</div>
<div class="RadioButtonHelperTextLabel3">not sure helper text</div>

</div>




我想像這樣使用 Append Yes 幫助文本到 Yes 使用 jQuery 但我的腳本正在添加多個/重復的 div:

   $("div.helperTextWrapper ").each(function(index) {

  $(this).find('.RadioButtonHelperTextLabel1').appendTo('.RadioButtonHelperText1');
   $(this).find('.RadioButtonHelperTextLabel2').appendTo('.RadioButtonHelperText2');
    $(this).find('.RadioButtonHelperTextLabel3').appendTo('.RadioButtonHelperText3');

    });


<div class="helperTextWrapper" >

<div class="radioTable">
 <div>
    <span>
       <label class="RadioButtonHelperText1">Yes
           <div class="RadioButtonHelperTextLabel1">Yes helper text</div>
        </label>
   </span>
</div>
 <div>
    <span>
       <label class="RadioButtonHelperText2">No
        <div class="RadioButtonHelperTextLabel2">no helper text</div>
        </label>
   </span>
</div>
</div>

</div>




<div class="helperTextWrapper" >

<div class="radioTable">
 <div>
    <span>
       <label class="RadioButtonHelperText1">Yes
           <div class="RadioButtonHelperTextLabel1">Yes helper text</div>
        </label>
   </span>
</div>
 <div>
    <span>
       <label class="RadioButtonHelperText2">No
        <div class="RadioButtonHelperTextLabel2">no helper text</div>
        </label>
   </span>
</div>
    <div>
    <span>
       <label class="RadioButtonHelperText3">Not sure
        <div class="RadioButtonHelperTextLabel3">not sure helper text</div>
        </label>
   </span>
</div>
</div>

</div>

````




$('.helperTextWrapper').each(function(){

$(this).find('.RadioButtonHelperTextLabel1').appendTo($(this).find('.RadioButtonHelperText1'));
$(this).find('.RadioButtonHelperTextLabel2').appendTo($(this).find('.RadioButtonHelperText2'));
$(this).find('.RadioButtonHelperTextLabel3').appendTo($(this).find('.RadioButtonHelperText3'));

});


https://jsfiddle.net/praveendubbaka/t71oae3b/46/

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM