Reputation: 18237
I'm trying to accomplish the follow copy elements from the one table to other when a user do a click in a button, the problem it's i don't know how copy an element modifying the id. I know that exit's a function called clone but i don't know if with this function if the best way
Upvotes: 0
Views: 62
Reputation: 6127
$('#buttonID').click(function(){
$('#yourelement').clone().attr('id','newID').appendTo('#newContainer');
});
Upvotes: 1
Reputation: 382636
I know that exit's a function called clone but i don't know if with this function if the best way
That's the easiest way AFAIK.
The .clone() method performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes. When used in conjunction with one of the insertion methods, .clone() is a convenient way to duplicate elements on a page.
Note that clone
clones the element along with data as well as any associated events. If you need to remove a certain event from cloned element, you can use the unbind
function.
Upvotes: 1