Event handlers not cloned when using traditional registration

Atom RSS

This site heavily relies on bug reports created by its readers. Anyone can report a bug and be published.

Main navigation:




Search reports by browser:

Registering events to an element using element.event=function() {...} does not carry over to clones of elements. This behavior seems improper.

My current workaround is to re-run whatever code that applies the behavior; re-clicking the button on the test page works in Firefox, but not in IE (probably an ID thing). I call that "not included".

Test page Workaround is not included
Reported by: Jay Eldridge.

(Orphaned), Explorer 5-6 Windows, Explorer Mac, Mozilla, Opera, Safari | Reported on 2 September 2005.

Comments

(Add your own)

Posted by Sebastian Redl on 2 September 2005

1

You can hardly call behaviour that is not specified by any standard and is consistent across all browsers a "bug". It may not be what you like and it may not make much sense, but ...
Look at it this way, at least it's consistent. Now what would interest me is the behaviour when using the other event model (W3 addEventListener for those that support it, IE attachEvent for IE).

Posted by Jay Eldridge on 3 September 2005

2

I think it's worth having it noted that a cloned element isn't, even if "bug" may not be quite as accurate as "quirk".

Posted by Maian on 5 September 2005

3

Hah, I just encountered this "bug" recently.

Indeed, it's hard to classify as a bug, since although the event handler should be stored as an attribute, the spec does not state HOW the handler should be serialized into a string to be stored into that attribute.

At this point, it's fair game for user agents to determine if the |node.onevent = handler| syntax should create/modify the attribute.

I haven't tested this, but on non-IE browsers, using the setAttribute() method should preserve the handler on clones. IE won't work here since it has an incorrect implementation of setAttribute.

Posted by Peter Siewert on 7 September 2005

4

I think the "buggy" behavior is due to the fact that the javascript object space and the DOM object space are actually two different spaces that, while closely tied together, are distinct. When an element is cloned, only the DOM portions are cloned. Anything setup using javascript will not be passed to the cloned object. See http://www.geocities.com/petersiewertweb/domClone.html for another example. I think the DOM event registraction functions actually modify the DOM object, while the "traditional" event registration functions do not.

Post a comment

Commenting guidelines:

  1. When quoting specs, articles or your own research, please include a URL of the document.
  2. Test your stuff. When reporting browser behaviour, make sure that your report is correct.

Yes