Reputation: 364
I want to clone a div one at a time when i click on a header
$("h3").click(function() { $("div").clone().insertAfter("div:last")); });
Right now it will clone all the divs and put them after the last one but i want to clone div1 then div2 etc.
Upvotes: 1
Views: 179
Reputation: 8728
you can use .each() method to get the correct requirement.
$("h3").click(function() {
$("div").each(function() {
$this = jQuery(this);
// do something with current div $this
$this.clone().insertAfter("div:last"));
// a bit better?
$this.parent().prepend($this.clone());
});
});
i hope this help you more.
Upvotes: 2
Reputation: 36000
Try each
:
$("h3").click(function() {
$.each($("div"), function() {
$(this).clone().insertAfter("div:last");
});
});
Upvotes: 1