Commits

Mark Raddatz  committed 6a0ee2d

Fix #13401: replaceWith(""). Close gh-1163.

  • Participants
  • Parent commits dc9b009

Comments (0)

Files changed (2)

File src/manipulation.js

 			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 ) {

File test/unit/manipulation.js

 	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 );