Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是故事。我的页面上的 div 中有一个无序列表。
编码:
<div id="move-me"> <ul> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> </ul> </div>
上面的代码位于页面的左侧,现在我要做的是,销毁 div 和 ul 元素,只留下链接。然后最后将这些链接附加到侧边栏列表。
有任何想法吗?
简单的!
$("#move-me").remove().find('a').appendTo("#somewhere-else");
一个例子。
您想从 LI 标签中删除链接,然后添加到侧边栏,然后删除无序列表。像这样的东西应该工作:
$('#move-me > a').appendTo('#sidebar'); $('#move-me').remove();