Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery clone div and append it after specific div

Tags:

jquery

clone

enter image description here

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 can I do that? Thanks.

This is my try code:

$("div[id^='car']:last").after('put the clone div here'); 
like image 799
cyberfly Avatar asked Jan 03 '12 04:01

cyberfly


1 Answers

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"); 
like image 150
letuboy Avatar answered Sep 21 '22 18:09

letuboy