Ariod
Ariod

Reputation: 5851

Dojo: Copying a node tree

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().

Upvotes: 1

Views: 713

Answers (2)

NickFitz
NickFitz

Reputation: 35041

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

Upvotes: 2

Eldar Djafarov
Eldar Djafarov

Reputation: 24685

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

Upvotes: 0

Related Questions