Skip to content

Commit 36a98b9

Browse files
committed
Make sure we use detach instead of remove in replaceWith. Fixes #5785.
1 parent 366039a commit 36a98b9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/manipulation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ jQuery.fn.extend({
216216
return this.each(function() {
217217
var next = this.nextSibling, parent = this.parentNode;
218218

219-
jQuery(this).remove();
219+
jQuery(this).detach();
220220

221221
if ( next ) {
222222
jQuery(next).before( value );

test/unit/manipulation.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
626626
});
627627

628628
var testReplaceWith = function(val) {
629-
expect(14);
629+
expect(16);
630630
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
631631
ok( jQuery("#replace")[0], 'Replace element with string' );
632632
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
@@ -648,6 +648,15 @@ var testReplaceWith = function(val) {
648648
ok( jQuery("#mark")[0], 'Replace element with set of elements' );
649649
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
650650

651+
reset();
652+
var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); });
653+
var y = jQuery('#yahoo').click(function(){ ok(true, "Previously bound click run." ); });
654+
y.replaceWith( tmp );
655+
tmp.click();
656+
y.click();
657+
658+
reset();
659+
651660
var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
652661
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
653662
equals( set.length, 1, "Replace the disconnected node." );

0 commit comments

Comments
 (0)