Search code examples
jqueryclone

jquery clone div and append it after specific div


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

Solution

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