Skip to content

Commit

Permalink
Make sure we use detach instead of remove in replaceWith. Fixes #5785.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Jan 11, 2010
1 parent 366039a commit 36a98b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/manipulation.js
Expand Up @@ -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 );
Expand Down
11 changes: 10 additions & 1 deletion test/unit/manipulation.js
Expand Up @@ -626,7 +626,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
});

var testReplaceWith = function(val) {
expect(14);
expect(16);
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
ok( jQuery("#replace")[0], 'Replace element with string' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
Expand All @@ -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("<div/>").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("<div/>").replaceWith(val("<span>test</span>"));
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." );
Expand Down

0 comments on commit 36a98b9

Please sign in to comment.