From: jeresig Date: Mon, 11 Jan 2010 20:57:45 +0000 (-0500) Subject: Make sure we use detach instead of remove in replaceWith. Fixes #5785. X-Git-Tag: 1.4rc1~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=36a98b95c2f3f7617ddf51beec7515acf67d98ba;p=jquery.git Make sure we use detach instead of remove in replaceWith. Fixes #5785. --- diff --git a/src/manipulation.js b/src/manipulation.js index 9ed22baaf..f2f6c7de6 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -216,7 +216,7 @@ jQuery.fn.extend({ return this.each(function() { var next = this.nextSibling, parent = this.parentNode; - jQuery(this).remove(); + jQuery(this).detach(); if ( next ) { jQuery(next).before( value ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index a7e1f7e45..52becfefb 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -626,7 +626,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() { }); var testReplaceWith = function(val) { - expect(14); + expect(16); jQuery('#yahoo').replaceWith(val( 'buga' )); ok( jQuery("#replace")[0], 'Replace element with string' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); @@ -648,6 +648,15 @@ var testReplaceWith = function(val) { ok( jQuery("#mark")[0], 'Replace element with set of elements' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); + reset(); + var tmp = jQuery("
").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); }); + var y = jQuery('#yahoo').click(function(){ ok(true, "Previously bound click run." ); }); + y.replaceWith( tmp ); + tmp.click(); + y.click(); + + reset(); + var set = jQuery("
").replaceWith(val("test")); equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); equals( set.length, 1, "Replace the disconnected node." );