Why is this “copy”(click) wrong, it binds all the previous handlers as well:
var add = function(element) {
var ele = element.clone(true);
$('.container').append(ele);
$('.copy', new).click(function(){ add(ele); });
}
Idea: I want to have an element text next to a “copy” button.
When I click “copy”, it clones the current row and append it to the container.
But this seems to be recursive…
The
trueparameter says:So you keep adding
clickevent handlers to the.cloneelement. Depending on your actual case, just don’t bind the event handler again:(I used
$(this).closest('tr')to get the parent row. Obviously you have to adjust it to your needs.)Update:
Or don’t pass
true: