jQuery的移动节点从其父 [英] jQuery move node out of its parent
本文介绍了jQuery的移动节点从其父的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我再次;)
抱歉打扰了亚勒但我要疯了这一点。
sorry for disturbing yall but i am going crazy with this.
例如。我有这个code:
e.g. i have this code:
<ul class="list">
<li>
<a href="#" >
<img src="IMAGE" />
SOME TEXT
</a>
</li>
<li>
<a href="#" >
<img src="ANOTHER IMAGE" />
SOME DIFFERENT TEXT
</a>
</li>
</ul>
我想图像prepended像这样的父节点
i want the images prepended to the parent node like this
<ul class="list">
<li>
<img src="IMAGE" />
<a href="#" >
SOME TEXT
</a>
</li>
<li>
<img src="ANOTHER IMAGE" />
<a href="#" >
SOME DIFFERENT TEXT
</a>
</li>
</ul>
在此先感谢
推荐答案
试试这个:
$('.list > li > a > img').each(function() {
$(this).insertBefore($(this).parent());
})
在 http://jsfiddle.net/alnitak/3nEVz/
修改我想出了一个更清洁的版本:
EDIT I came up with a cleaner version:
$('.list > li > a > img').each(function() {
$(this).parent().before(this);
})
这篇关于jQuery的移动节点从其父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文