0

我想克隆一个 div 并将其附加到使用 jQuery 的 HTML 表中的另一个元素。例如

我想复制 divsection_title并将其立即附加到append_class跨度中。换句话说,div section_title FIRST TITLE将被附加到 span 中append_class,同样如此。

这是HTML

<tr class="tr_class">
<th scope="row">
<div class="section_title">FIRST TITLE</div>
</th>
<td>
RANDOM CONTENT...
</td>
</tr>
<span class="append_class"></span>

<tr class="tr_class">
<th scope="row">
<div class="section_title">SECOND TITLE</div>
</th>
<td>
RANDOM CONTENT...
</td>
</tr>
<span class="append_class"></span>


<tr class="tr_class">
<th scope="row">
<div class="section_title">THIRD TITLE</div>
</th>
<td>
RANDOM CONTENT...
</td>
</tr>
<span class="append_class"></span>

我的尝试失败了。

var cloneTitle= $('.tr_class').find('.section_title').clone();
$('.append_class').html(cloneTitle);

它确实克隆但它会克隆所有section_title并相应地附加它们。

对此的任何指导将不胜感激。

提前致谢

4

1 回答 1

1

如果我明白你的意思你需要使用.each()$(this)

$('.tr_class').each(function(){
   var cloneTitle = $(this).find('.section_title').clone();
    $(this).next('.append_class').html(cloneTitle);
});
于 2017-05-02T15:24:55.357 回答