Skip to content

Commit

Permalink
Fix #13233: re-allow .replaceWith of text nodes. Close gh-1137.
Browse files Browse the repository at this point in the history
(cherry picked from commit 6b1b0a2)
  • Loading branch information
gibson042 committed Jan 16, 2013
1 parent 306b698 commit a96aa9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/manipulation.js
Expand Up @@ -243,15 +243,9 @@ jQuery.fn.extend({
var next = this.nextSibling, var next = this.nextSibling,
parent = this.parentNode; parent = this.parentNode;


if ( parent && this.nodeType === 1 || this.nodeType === 11 ) { if ( parent ) {

jQuery( this ).remove(); jQuery( this ).remove();

parent.insertBefore( elem, next );
if ( next ) {
next.parentNode.insertBefore( elem, next );
} else {
parent.appendChild( elem );
}
} }
}); });
}, },
Expand Down
6 changes: 5 additions & 1 deletion test/unit/manipulation.js
Expand Up @@ -1107,7 +1107,7 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
var testReplaceWith = function( val ) { var testReplaceWith = function( val ) {


var tmp, y, child, child2, set, non_existent, $div, var tmp, y, child, child2, set, non_existent, $div,
expected = 22; expected = 23;


expect( expected ); expect( expected );


Expand All @@ -1134,6 +1134,10 @@ var testReplaceWith = function( val ) {
ok( jQuery("#mark")[ 0 ], "Replace element with set of elements" ); ok( jQuery("#mark")[ 0 ], "Replace element with set of elements" );
ok( !jQuery("#groups")[ 0 ], "Verify that original element is gone, after 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() { tmp = jQuery("<div/>").appendTo("#qunit-fixture").click(function() {
ok( true, "Newly bound click run." ); ok( true, "Newly bound click run." );
Expand Down

0 comments on commit a96aa9e

Please sign in to comment.