W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2002

Re: cloneNode() and events

From: Jonathan Watt <0jaw@qlink.queensu.ca>
Date: Wed, 20 Mar 2002 09:44:28 -0500
Message-ID: <3C98A04C.1040907@qlink.queensu.ca>
To: M.Hompus@gac.nl
CC: www-dom@w3.org
That part of the DOM behaviour is specified in DOM-Level-2-Events. See 
the second paragraph under the "Interface EventListener" heading at 

"When a Node is copied using the cloneNode method the EventListeners 
attached to the source Node are not attached to the copied Node. If the 
user wishes the same EventListeners to be added to the newly created 
copy the user must add them manually."

Personally I just run any objects that I clone through an "event hookup" 



M.Hompus@gac.nl wrote:
> I do a lot of j(ava)scripting with the DOM, now I've written some code that
> makes a (prototype) object that is cloned several times. This object has
> also an event attached. In Internet Explorer this event is available on
> each node that was cloned, in Mozilla this isn't happening.
> When I use the same code to attach an event to a node which is not cloned
> it all just works fine. Because Mozilla normally is acting like it should,
> following the DOM standard I looked what was written about cloneNode and
> events. Surprisingly there is nothing said about event already on a node
> which is cloned.
> What should be the correct action? Should events be cloned? I hope it
> should, and I think it has to be specified in the DOM(-core).
> My code of the node:
> // Create prototype image
> var protoImg = doc.createElement('img');
> protoImg.src = './images/zoom.gif';
> protoImg.style.width = '16px';
> protoImg.style.height = '16px';
> protoImg.style.marginLeft = '2px';
> protoImg.style.verticalAlign = 'middle';
> protoImg.alt = protoImg.title = aProperties[1];
> try {
>      // Mozilla
>      protoImg.addEventListener('click', FL_DrawZoom, false);
> } catch(e) {
>      // Internet Explorer
>      protoImg.attachEvent('onclick', FL_DrawZoom);
> }
> The section of the DOM2-core about cloneNode():
> cloneNode
> Returns a duplicate of this node, i.e., serves as a generic copy
> constructor for nodes. The duplicate node has no parent; (parentNode is
> null.).
> Cloning an Element copies all attributes and their values, including those
> generated by the XML processor to represent defaulted attributes, but this
> method does not copy any text it contains unless it is a deep clone, since
> the text is contained in a child Text node. Cloning an Attribute directly,
> as opposed to be cloned as part of an Element cloning operation, returns a
> specified attribute (specified is true). Cloning any other type of node
> simply returns a copy of this node.
> Note that cloning an immutable subtree results in a mutable copy, but the
> children of an EntityReference clone are readonly. In addition, clones of
> unspecified Attr nodes are specified. And, cloning Document, DocumentType,
> Entity, and Notation nodes is implementation dependent.
> Parameters
>      deep of type boolean
>      If true, recursively clone the subtree under the specified node; if
> false, clone only the node itself (and its attributes, if it is an
> Element).
> Return Value
>      Node
>      The duplicate node.
> No Exceptions
Received on Wednesday, 20 March 2002 10:10:49 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:09 UTC