Commit 551c2c9f authored by Rod Vagg's avatar Rod Vagg Committed by Rick Waldron

Fixes #12449. make replaceWith() clone elements where required. Closes gh-920

parent 13449a99
...@@ -258,32 +258,29 @@ jQuery.fn.extend({ ...@@ -258,32 +258,29 @@ jQuery.fn.extend({
value = jQuery( value ).detach(); value = jQuery( value ).detach();
} }
this.each( function( i ) { return this.domManip( [ value ], true, function( elem, i ) {
var next = this.nextSibling, var next, parent;
parent = this.parentNode,
// HTML argument replaced by "this" element
// 1. There were no supporting tests
// 2. There was no internal code relying on this
// 3. There was no documentation of an html argument
val = !isFunc ? value : value.call( this, i, this );
if ( isDisconnected( this ) ) { if ( isDisconnected( this ) ) {
// for disconnected elements, we replace with the new content in the set. We use // for disconnected elements, we simply replace
// clone here to ensure that each replaced instance is unique // with the new content in the set
self[ i ] = jQuery( val ).clone()[ 0 ]; self[ i ] = elem;
return; return;
} }
jQuery( this ).remove(); if ( this.nodeType === 1 || this.nodeType === 11 ) {
next = this.nextSibling;
parent = this.parentNode;
if ( next ) { jQuery( this ).remove();
jQuery( next ).before( val );
} else { if ( next ) {
jQuery( parent ).append( val ); next.parentNode.insertBefore( elem, next );
} else {
parent.appendChild( elem );
}
} }
}); });
return this;
}, },
detach: function( selector ) { detach: function( selector ) {
...@@ -344,7 +341,8 @@ jQuery.fn.extend({ ...@@ -344,7 +341,8 @@ jQuery.fn.extend({
table && jQuery.nodeName( this[i], "table" ) ? table && jQuery.nodeName( this[i], "table" ) ?
findOrAppend( this[i], "tbody" ) : findOrAppend( this[i], "tbody" ) :
this[i], this[i],
node node,
i
); );
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment