]> source.dussan.org Git - jquery.git/commitdiff
Fix #13401: replaceWith(""). Close gh-1163.
authorMark Raddatz <mraddatz@gmail.com>
Thu, 7 Feb 2013 21:43:25 +0000 (05:43 +0800)
committerRichard Gibson <richard.gibson@gmail.com>
Fri, 8 Feb 2013 14:49:14 +0000 (09:49 -0500)
src/manipulation.js
test/unit/manipulation.js

index d50ebddf7c5398732ea5a21a7cffdea48fd7106a..a5a1a397596ccd4ffebe85c21722cb59bba8b30b 100644 (file)
@@ -241,15 +241,17 @@ jQuery.fn.extend({
                        value = jQuery( value ).not( this ).detach();
                }
 
-               return this.domManip( [ value ], true, function( elem ) {
-                       var next = this.nextSibling,
-                               parent = this.parentNode;
-
-                       if ( parent ) {
-                               jQuery( this ).remove();
-                               parent.insertBefore( elem, next );
-                       }
-               });
+               return value !== "" ?
+                       this.domManip( [ value ], true, function( elem ) {
+                               var next = this.nextSibling,
+                                       parent = this.parentNode;
+
+                               if ( parent ) {
+                                       jQuery( this ).remove();
+                                       parent.insertBefore( elem, next );
+                               }
+                       }) :
+                       this.remove();
        },
 
        detach: function( selector ) {
index 5c994a027c1dfa0b319984905b128c6206226d3d..01d53a0a12c72f7d2554ca56ef7558e5aca6ec87 100644 (file)
@@ -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");
 });
 
+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() {
 
        expect( 10 );