Skip to content
Permalink
Browse files
Fix for #921 (IE clones events)
  • Loading branch information
brandonaaron committed May 14, 2007
1 parent d0c6858 commit 108f308eaae62a78bd4dc8863f8c026f8828ef48
Showing with 23 additions and 4 deletions.
  1. +23 −4 src/jquery/jquery.js
@@ -852,11 +852,30 @@ jQuery.fn = jQuery.prototype = {
* @cat DOM/Manipulation
*/
clone: function(deep) {
return this.pushStack( jQuery.map( this, function(a){
a = a.cloneNode( deep != undefined ? deep : true );
a.$events = null; // drop $events expando to avoid firing incorrect events
return a;
// Need to remove events on the element and its descendants
var $this = this.add(this.find("*"));
$this.each(function() {
this._$events = {};
for (var type in this.$events)
this._$events[type] = jQuery.extend({},this.$events[type]);
}).unbind();

// Do the clone
var r = this.pushStack( jQuery.map( this, function(a){
return a.cloneNode( deep != undefined ? deep : true );
}) );

// Add the events back to the original and its descendants
$this.each(function() {
var events = this._$events;
for (var type in events)
for (var handler in events[type])
jQuery.event.add(this, type, events[type][handler], events[type][handler].data);
this._$events = null;
});

// Return the cloned set
return r;
},

/**

0 comments on commit 108f308

Please sign in to comment.