views:

68

answers:

2

I'm using Dojo as JavaScript framework. What I would like to do is copy a tree of nodes and put it under the copied tree. Specifically, I have a table row with plenty of code within it. I would like to add a new table row that is the exact copy of the above row, with some ids changed here and there.

What would be the best way to do this?

I was thinking of making a deep copy of the original row and provide it to document.createElement().

A: 

I think the simpliest and fastest way to do this is to copy innerHTML in new tr node. You can change ids with regexp.

Eldar Djafarov
+1  A: 

The DOM method cloneNode will do what you want; pass true to it to make a deep copy.

NickFitz