我需要将文本包裹在带有跨度的 div 内。
<div class="item">
<span class="count"></span>
Text that needs to be wrapped.
</div>
<div class="item">
<span class="count"></span>
Text that needs to be wrapped.
</div>
<div class="item">
<span class="count"></span>
Text that needs to be wrapped.
</div>
尝试过,但并没有真正起作用......
$('.item').text().wrap('<span class="new" />');
最佳答案
您可以使用contents()来做到这一点和 .eq()
$('.item').each(function(i, v) {
$(v).contents().eq(2).wrap('<span class="new"/>')
});
关于jquery - 将文本包裹在元素内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13652140/