Permalink
Browse files

Handle the case of an empty string. Fixes #13401.

  • Loading branch information...
1 parent f3db084 commit b510d24c4b7127c30fa066d5ffc4c8aeb47e31d5 @markraddatz committed Feb 7, 2013
Showing with 23 additions and 0 deletions.
  1. +6 −0 src/manipulation.js
  2. +17 −0 test/unit/manipulation.js
View
@@ -241,6 +241,12 @@ jQuery.fn.extend({
value = jQuery( value ).not( this ).detach();
}
+ if ( value === "" ) {
+ return this.each(function() {
@dmethvin
dmethvin Feb 7, 2013

Can just be return this.remove(); I think?

@dmethvin
dmethvin Feb 7, 2013

Wondering whether we should be catching other falsy values rather than passing them to domManip. Also now that I look at it, most of the other appending methods allow multiple args but we don't here. Kinda strange.

+ jQuery( this ).remove();
+ });
+ }
+
return this.domManip( [ value ], true, function( elem ) {
var next = this.nextSibling,
parent = this.parentNode;
@@ -2225,3 +2225,20 @@ test( "Make sure specific elements with content created correctly (#13232)", 20,
ok( jQuery.nodeName( this, results[ i ] ) );
});
});
+
+test( "replaceWith() - Handle the case of an empty string (#13401)", 4, function() {
+ var div = jQuery( "<div/>" ),
+ p = jQuery( "<p/>" );
+
+ div.html( p );
+ equal( div.html(), "<p></p>", "Check element exists" );
+
+ p.replaceWith( " " );
+ equal( div.html(), " ", "Check element is replaced" );
+
+ div.html( p );
+ equal( div.html(), "<p></p>", "Check element exists" );
+
+ p.replaceWith( "" );
+ equal( div.html(), "", "Check element is replaced" );
+});

0 comments on commit b510d24

Please sign in to comment.