gpt4 book ai didi

javascript - 从多个嵌套位置删除没有内容的类的 div

转载 作者:行者123 更新时间:2023-11-28 19:36:27 24 4
gpt4 key购买 nike

我有:

<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com