Skip to content

Commit

Permalink
Fix #13401: replaceWith(""). Close gh-1163.
Browse files Browse the repository at this point in the history
  • Loading branch information
markraddatz authored and gibson042 committed Feb 8, 2013
1 parent dc9b009 commit 6a0ee2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/manipulation.js
Expand Up @@ -241,15 +241,17 @@ jQuery.fn.extend({
value = jQuery( value ).not( this ).detach(); value = jQuery( value ).not( this ).detach();
} }


return this.domManip( [ value ], true, function( elem ) { return value !== "" ?
var next = this.nextSibling, this.domManip( [ value ], true, function( elem ) {
parent = this.parentNode; var next = this.nextSibling,

parent = this.parentNode;
if ( parent ) {
jQuery( this ).remove(); if ( parent ) {
parent.insertBefore( elem, next ); jQuery( this ).remove();
} parent.insertBefore( elem, next );
}); }
}) :
this.remove();
}, },


detach: function( selector ) { detach: function( selector ) {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/manipulation.js
Expand Up @@ -1219,6 +1219,15 @@ test( "replaceWith(string) for more than one element", function() {
equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced"); equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced");
}); });


test( "replaceWith(\"\") (#13401)", 4, function() {
expect( 1 );

var div = jQuery("<div><p></p></div>");

div.children().replaceWith("");
equal( div.html().toLowerCase(), "", "Replacing with empty string removes element" );
});

test( "replaceAll(String|Element|Array<Element>|jQuery)", function() { test( "replaceAll(String|Element|Array<Element>|jQuery)", function() {


expect( 10 ); expect( 10 );
Expand Down

0 comments on commit 6a0ee2d

Please sign in to comment.