Skip to content

Commit 4b70f00

Browse files
committed
Made .clone(true) also copy over element data. Fixes #4191.
1 parent f6a0bf6 commit 4b70f00

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/manipulation.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,7 @@ function cloneCopyEvent(orig, ret) {
277277
return;
278278
}
279279

280-
var events = jQuery.data( orig[i], "events" );
281-
282-
for ( var type in events ) {
283-
for ( var handler in events[ type ] ) {
284-
jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
285-
}
286-
}
280+
jQuery.data( this, jQuery.data( orig[i++] ) );
287281
});
288282
}
289283

test/unit/manipulation.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
549549
});
550550

551551
test("clone()", function() {
552-
expect(28);
552+
expect(30);
553553
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
554554
var clone = jQuery('#yahoo').clone();
555555
equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
@@ -594,6 +594,11 @@ test("clone()", function() {
594594
div = div.clone(true);
595595
equals( div.length, 1, "One element cloned" );
596596
equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
597+
598+
div = jQuery("<div/>").data({ a: true, b: true });
599+
div = div.clone(true);
600+
equals( div.data("a"), true, "Data cloned." );
601+
equals( div.data("b"), true, "Data cloned." );
597602
});
598603

599604
if (!isLocal) {

0 commit comments

Comments
 (0)