diff options
author | Rod Vagg <rod@vagg.org> | 2012-12-04 21:50:22 -0500 |
---|---|---|
committer | Rick Waldron <waldron.rick@gmail.com> | 2012-12-04 21:50:22 -0500 |
commit | 551c2c9f4ac776b6d53600c452ad40a4b4d6670b (patch) | |
tree | e78dbc837fdafea29979426af3697d11962e906e /src/manipulation.js | |
parent | 13449a99b2b279a7ae6401b8373d20504362213d (diff) | |
download | jquery-551c2c9f4ac776b6d53600c452ad40a4b4d6670b.tar.gz jquery-551c2c9f4ac776b6d53600c452ad40a4b4d6670b.zip |
Fixes #12449. make replaceWith() clone elements where required. Closes gh-920
Diffstat (limited to 'src/manipulation.js')
-rw-r--r-- | src/manipulation.js | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/manipulation.js b/src/manipulation.js index 6cde99404..f07d6bbfb 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -258,32 +258,29 @@ jQuery.fn.extend({ value = jQuery( value ).detach(); } - this.each( function( i ) { - var next = this.nextSibling, - 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 ); + return this.domManip( [ value ], true, function( elem, i ) { + var next, parent; if ( isDisconnected( this ) ) { - // for disconnected elements, we replace with the new content in the set. We use - // clone here to ensure that each replaced instance is unique - self[ i ] = jQuery( val ).clone()[ 0 ]; + // for disconnected elements, we simply replace + // with the new content in the set + self[ i ] = elem; return; } - jQuery( this ).remove(); + if ( this.nodeType === 1 || this.nodeType === 11 ) { + next = this.nextSibling; + parent = this.parentNode; - if ( next ) { - jQuery( next ).before( val ); - } else { - jQuery( parent ).append( val ); + jQuery( this ).remove(); + + if ( next ) { + next.parentNode.insertBefore( elem, next ); + } else { + parent.appendChild( elem ); + } } }); - - return this; }, detach: function( selector ) { @@ -344,7 +341,8 @@ jQuery.fn.extend({ table && jQuery.nodeName( this[i], "table" ) ? findOrAppend( this[i], "tbody" ) : this[i], - node + node, + i ); } |