@@ -442,38 +442,28 @@ jQuery.fn.extend({
442
442
} ,
443
443
444
444
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 ] ;
451
446
452
447
// Make the changes, replacing each context element with the new content
453
448
this . domManip ( arguments , function ( elem ) {
454
- var next = args [ i ++ ] ,
455
- parent = args [ i ++ ] ;
449
+ arg = this . parentNode ;
456
450
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 ) ;
464
455
}
465
- // Allow new content to include elements from the context set
466
- } , true ) ;
456
+ } ) ;
467
457
468
458
// 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 ( ) ;
470
460
} ,
471
461
472
462
detach : function ( selector ) {
473
463
return this . remove ( selector , true ) ;
474
464
} ,
475
465
476
- domManip : function ( args , callback , allowIntersection ) {
466
+ domManip : function ( args , callback ) {
477
467
478
468
// Flatten any nested arrays
479
469
args = concat . apply ( [ ] , args ) ;
@@ -495,12 +485,12 @@ jQuery.fn.extend({
495
485
if ( isFunction ) {
496
486
args [ 0 ] = value . call ( this , index , self . html ( ) ) ;
497
487
}
498
- self . domManip ( args , callback , allowIntersection ) ;
488
+ self . domManip ( args , callback ) ;
499
489
} ) ;
500
490
}
501
491
502
492
if ( l ) {
503
- fragment = jQuery . buildFragment ( args , this [ 0 ] . ownerDocument , false , ! allowIntersection && this ) ;
493
+ fragment = jQuery . buildFragment ( args , this [ 0 ] . ownerDocument , false , this ) ;
504
494
first = fragment . firstChild ;
505
495
506
496
if ( fragment . childNodes . length === 1 ) {
0 commit comments