@@ -442,38 +442,28 @@ jQuery.fn.extend({
442442 } ,
443443
444444 replaceWith : function ( ) {
445- var
446- // Snapshot the DOM in case .domManip sweeps something relevant into its fragment
447- args = jQuery . map ( this , function ( elem ) {
448- return [ elem . nextSibling , elem . parentNode ] ;
449- } ) ,
450- i = 0 ;
445+ var arg = arguments [ 0 ] ;
451446
452447 // Make the changes, replacing each context element with the new content
453448 this . domManip ( arguments , function ( elem ) {
454- var next = args [ i ++ ] ,
455- parent = args [ i ++ ] ;
449+ arg = this . parentNode ;
456450
457- if ( parent ) {
458- // Don't use the snapshot next if it has moved (#13810)
459- if ( next && next . parentNode !== parent ) {
460- next = this . nextSibling ;
461- }
462- jQuery ( this ) . remove ( ) ;
463- parent . insertBefore ( elem , next ) ;
451+ jQuery . cleanData ( getAll ( this ) ) ;
452+
453+ if ( arg ) {
454+ arg . replaceChild ( elem , this ) ;
464455 }
465- // Allow new content to include elements from the context set
466- } , true ) ;
456+ } ) ;
467457
468458 // Force removal if there was no new content (e.g., from empty arguments)
469- return i ? this : this . remove ( ) ;
459+ return arg && ( arg . length || arg . nodeType ) ? this : this . remove ( ) ;
470460 } ,
471461
472462 detach : function ( selector ) {
473463 return this . remove ( selector , true ) ;
474464 } ,
475465
476- domManip : function ( args , callback , allowIntersection ) {
466+ domManip : function ( args , callback ) {
477467
478468 // Flatten any nested arrays
479469 args = concat . apply ( [ ] , args ) ;
@@ -495,12 +485,12 @@ jQuery.fn.extend({
495485 if ( isFunction ) {
496486 args [ 0 ] = value . call ( this , index , self . html ( ) ) ;
497487 }
498- self . domManip ( args , callback , allowIntersection ) ;
488+ self . domManip ( args , callback ) ;
499489 } ) ;
500490 }
501491
502492 if ( l ) {
503- fragment = jQuery . buildFragment ( args , this [ 0 ] . ownerDocument , false , ! allowIntersection && this ) ;
493+ fragment = jQuery . buildFragment ( args , this [ 0 ] . ownerDocument , false , this ) ;
504494 first = fragment . firstChild ;
505495
506496 if ( fragment . childNodes . length === 1 ) {
0 commit comments