jQuery的:appendTo父 [英] jQuery: appendTo parent

查看:120
本文介绍了jQuery的:appendTo父的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到appendTo工作。我该怎么办错了?

I can't seem to get the appendTo to work. What do I do wrong?

$('div:nth-child(2n) img').appendTo(parent);

当前的标记:

<div class="container">
  <img src="123.jpg" />
  <p>Hey</p>
</div>
<div class="container">
  <img src="123.jpg" />
  <p>Hey</p>
</div>

我想这样的输出:

I want this output:

<div class="container">
  <p>Hey</p>
  <img src="123.jpg" />
</div>
<div class="container">
  <p>Hey</p>
  <img src="123.jpg" />
</div>

请帮我家伙...我撕我的每一分钟的头发..:-S

Please help me guys... I'm tearing my hair of every minute.. :-S

推荐答案

以下就足够了:

$("div>img").each(function(){
    $(this).appendTo($(this).parent());
});

请参阅在这里工作: http://jsfiddle.net/EtxqL/

您不能从'选择'参数推断出每个项目的父appendTo()。做你想做什么的唯一方式是遍历的项目,追加每一个其父。退房的API在下面的链接。

You can't infer each item's parent from the 'selector' parameter to appendTo(). The only way to do what you want is to loop through the items, appending each one to its parent. Check out the APIs in the following link.

.appendTo()API

。每个API

这篇关于jQuery的:appendTo父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆