jquery clone div and append it after specific div

cyberfly picture cyberfly · Jan 3, 2012 · Viewed 131.5k times · Source

enter image description here

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.

This is my try code:

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

Answer

letuboy picture letuboy · Jan 3, 2012

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");