jQuery克隆div并将其附加到特定的div之后 [英] jquery clone div and append it after specific div

查看:651
本文介绍了jQuery克隆div并将其附加到特定的div之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我要从上面的图片中克隆ID为#car2的div,并将其附加到id为car的最后一个div之后,在本示例中为id#car5.我该怎么做? 谢谢.

Hi guys, from the picture above, I want to clone the div with id #car2 and append it after the last div with id start with car, in this example id #car5. How i can do that? Thanks.

这是我的尝试代码:

$("div[id^='car']:last").after('put the clone div here');

推荐答案

您可以使用clone,然后由于每个div都有一个car_well类,因此您可以使用insertAfter在最后一个div之后插入.

You can use clone, and then since each div has a class of car_well you can use insertAfter to insert after the last div.

$("#car2").clone().insertAfter("div.car_well:last");

这篇关于jQuery克隆div并将其附加到特定的div之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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