使用jQuery在其同级中移动元素
我想在以下html中的“p”元素中移动图像:使用jQuery在其同级中移动元素,jquery,Jquery,我想在以下html中的“p”元素中移动图像: <div class="entery-post-excerpts"> <p>content1</p> <a href="#" class="alignrightthumb"><img width="210" height="158" src="http://imageurl"></a> </div> 或 似乎它不起作用。。。我如何才能做到这一点?那么您的问题是什么?
<div class="entery-post-excerpts">
<p>content1</p>
<a href="#" class="alignrightthumb"><img width="210" height="158" src="http://imageurl"></a>
</div>
或
似乎它不起作用。。。我如何才能做到这一点?那么您的问题是什么?想知道哪一个更好吗?@Rajaparbhu。很抱歉给你带来了困惑。我编辑了我的问题。似乎它不起作用。我的脚本中有错误吗?你的代码应该可以工作@彼得:你能描述一下“它不起作用”吗。我发现我的html代码中有一个小错误(缺少引号)。现在,它的工作如预期。谢谢你的帮助。
<div class="entery-post-excerpts">
<p>content1<a href="#" class="alignrightthumb"><img width="210" height="158" src="http://imageurl"></a></p>
</div>
$('.alignrightthumb').each(function() {
$(this).appendTo($(this).parent().chidlren('p:first-child'));
});
$('.alignrightthumb').each(function() {
$(this).appendTo($(this).siblings('p'));
});