我有:
<div class="stuff">
<div class="removeme">
<div class="iamfree">
iamfree
<div class="removeme">
<div class="ishouldbefreetoo">
ishouldbefreetoo
</div>
</div>
</div>
</div>
</div>
我想要:
<div class="stuff">
<div class="iamfree">
iamfree
<div class="ishouldbefreetoo">
ishouldbefreetoo
</div>
</div>
</div>
在这里尝试了 jQuery 的 unwrap() 函数:http://jsfiddle.net/adyz/7d947wja/
此外,克隆元素在展开时表现得很奇怪。
最佳答案
您需要调用unwrap()关于要删除的元素的内容。
$('.removeme').contents().unwrap()
演示:Fiddle
Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
关于javascript - 从多个嵌套位置删除没有内容的类的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25792455/