@@ -300,7 +300,7 @@ jQuery.fn.extend({
300300 } ,
301301
302302 domManip : function ( args , table , callback ) {
303- var results , first , value = args [ 0 ] , scripts = [ ] , fragment ;
303+ var results , first , value = args [ 0 ] , scripts = [ ] , fragment , parent ;
304304
305305 // We can't cloneNode fragments that contain checked, in WebKit
306306 if ( ! jQuery . support . checkClone && arguments . length === 3 && typeof value === "string" && rchecked . test ( value ) ) {
@@ -318,9 +318,12 @@ jQuery.fn.extend({
318318 }
319319
320320 if ( this [ 0 ] ) {
321+ parent = value && value . parentNode ;
322+
321323 // If we're in a fragment, just use that instead of building a new one
322- if ( args [ 0 ] && args [ 0 ] . parentNode && args [ 0 ] . parentNode . nodeType === 11 ) {
323- results = { fragment : args [ 0 ] . parentNode } ;
324+ if ( parent && parent . nodeType === 11 && parent . childNodes . length === this . length ) {
325+ results = { fragment : parent } ;
326+
324327 } else {
325328 results = buildFragment ( args , this , scripts ) ;
326329 }
@@ -429,9 +432,10 @@ jQuery.each({
429432 replaceAll : "replaceWith"
430433} , function ( name , original ) {
431434 jQuery . fn [ name ] = function ( selector ) {
432- var ret = [ ] , insert = jQuery ( selector ) ;
435+ var ret = [ ] , insert = jQuery ( selector ) ,
436+ parent = this . length === 1 && this [ 0 ] . parentNode ;
433437
434- if ( this . length === 1 && this [ 0 ] . parentNode && this [ 0 ] . parentNode . nodeType === 11 && insert . length === 1 ) {
438+ if ( parent && parent . nodeType === 11 && parent . childNodes . length === 1 && insert . length === 1 ) {
435439 insert [ original ] ( this [ 0 ] ) ;
436440 return this ;
437441
0 commit comments