Yup, I just found that myself.  Finally got the right combination of search
terms in Google to get what I needed.

5.2.3.8. cloneNode
For elements that already exist, a copy method allows you to duplicate
elements to avoid having to recreate them from scratch. cloneNode, which is
a method on the element object rather than the document, returns a copy of
the given node. 

<script>
  // this is untested --pete
  var element = document.getElementById('my-id');
  var clone = element.cloneNode(false);
  dump(`element='+element+'\n');
  dump(`clone='+clone+'\n');
</script>The method takes a Boolean-optional parameter that specifies
whether the copy is "deep." Deep copies duplicate all descendants of a node
as well as the node itself. 

So the code Dave suggest works perfectly.
protoRow = document.getElementById("One").cloneNode(true);

Thanks.

--------------
Ian Skinner
Web Programmer
BloodSource
Sacramento, CA


-----Original Message-----
From: Dave Watts [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 31, 2003 11:21 AM
To: CF-Talk
Subject: RE: OT JavaScript Object Copy


> Apparently this is much more difficult then it probably 
> should be. But I can figure out how to make a true copy 
> of DOM object with JavaScript, instead of just a copy 
> of the pointer to the object.
> 
> For Example:
> 
> protoRow = (document.getElementById("One"));
> 
> I would like protoRow to be a true deep copy of the 
> current state of row "One", that I can use later on to 
> create new rows, even though by that time the state of 
> row one will have change significantly.

I think it's Node.cloneNode(true). The Boolean argument specifies the
creation of a deep copy. So, in your case, you could have this, I think:

protoRow = document.getElementById("One").cloneNode(true);

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. 
http://www.fusionauthority.com/ads.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to