From 6b1b0a26b4d485b4d9f334286efed5dfe33e3f3f Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 16 Jan 2013 12:55:56 -0500 Subject: [PATCH] Fix #13233: re-allow .replaceWith of text nodes. Close gh-1137. --- src/manipulation.js | 10 ++-------- test/unit/manipulation.js | 6 +++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 9f1ecfa7f..34309d0c9 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -269,15 +269,9 @@ jQuery.fn.extend({ var next = this.nextSibling, parent = this.parentNode; - if ( parent && this.nodeType === 1 || this.nodeType === 11 ) { - + if ( parent ) { jQuery( this ).remove(); - - if ( next ) { - next.parentNode.insertBefore( elem, next ); - } else { - parent.appendChild( elem ); - } + parent.insertBefore( elem, next ); } }); }, diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index aac966731..3ee260d7e 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1149,7 +1149,7 @@ test( "insertAfter(String|Element|Array|jQuery)", function() { var testReplaceWith = function( val ) { var tmp, y, child, child2, set, non_existent, $div, - expected = 22; + expected = 23; expect( expected ); @@ -1176,6 +1176,10 @@ var testReplaceWith = function( val ) { ok( jQuery("#mark")[ 0 ], "Replace element with set of elements" ); ok( !jQuery("#groups")[ 0 ], "Verify that original element is gone, after set of elements" ); + tmp = jQuery("content")[0]; + jQuery("#anchor1").contents().replaceWith( val(tmp) ); + deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" ); + tmp = jQuery("
").appendTo("#qunit-fixture").click(function() { ok( true, "Newly bound click run." ); -- 2.39.5