我正在尝试删除父标签, 但删除父标签不应删除其子元素。 child 应该附加上一个标签
代码如下:
<div class="mask">
<ul id="TickerT" class="news">
<ul class="tweet_list">
<li class="first odd">
<span class="tweet_time">about 8 minutes ago</a></span>
<span class="tweet_join"></span>
<span class="tweet_text">test test…</a></span>
</li>
</ul>
</ul>
</div>
</div>
至少有 5 个 <li>
现在我想删除 <ul class="tweet_list">
.
我用 jQuery 的 replaceWith 试过了但没有结果。
这是我从网站上使用的代码
var jj = $("ul.tweet_list").contents()
$(".tweet_list").replaceWith(jj);
但这没有用。
我想要的是删除<ul class="tweet_list">
但不是 <li>
其中<ul>
.
感谢帮助,谢谢..
最佳答案
您可以调用unwrap()列表项上的方法:
$("ul.tweet_list > li").unwrap();
这将删除 .tweet_list
<ul>
元素并重新设置 <li>
的父级#TickerT
下的元素(及其 sibling ,如果有的话) <ul>
元素。
关于javascript - jQuery : Removing parent tag not the child of that parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9209391/