]> source.dussan.org Git - jquery.git/commitdiff
Fix #13233: re-allow .replaceWith of text nodes. Close gh-1137.
authorRichard Gibson <richard.gibson@gmail.com>
Wed, 16 Jan 2013 17:55:56 +0000 (12:55 -0500)
committerRichard Gibson <richard.gibson@gmail.com>
Wed, 16 Jan 2013 18:54:01 +0000 (13:54 -0500)
src/manipulation.js
test/unit/manipulation.js

index 9f1ecfa7f0cb055848fd7cbbd70c60597ec2ee72..34309d0c94f01adfc211ab6298f89dd589be0d8a 100644 (file)
@@ -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 );
                        }
                });
        },
index aac966731ad703a5582ded27794bf87aa2a5dce9..3ee260d7e217cf97425d05df7981997bbe9306fa 100644 (file)
@@ -1149,7 +1149,7 @@ test( "insertAfter(String|Element|Array<Element>|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("<b>content</b>")[0];
+       jQuery("#anchor1").contents().replaceWith( val(tmp) );
+       deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" );
+
 
        tmp = jQuery("<div/>").appendTo("#qunit-fixture").click(function() {
                ok( true, "Newly bound click run." );