@@ -258,32 +258,29 @@ jQuery.fn.extend({
258
258
value = jQuery ( value ) . detach ( ) ;
259
259
}
260
260
261
- this . each ( function ( i ) {
262
- var next = this . nextSibling ,
263
- parent = this . parentNode ,
264
- // HTML argument replaced by "this" element
265
- // 1. There were no supporting tests
266
- // 2. There was no internal code relying on this
267
- // 3. There was no documentation of an html argument
268
- val = ! isFunc ? value : value . call ( this , i , this ) ;
261
+ return this . domManip ( [ value ] , true , function ( elem , i ) {
262
+ var next , parent ;
269
263
270
264
if ( isDisconnected ( this ) ) {
271
- // for disconnected elements, we replace with the new content in the set. We use
272
- // clone here to ensure that each replaced instance is unique
273
- self [ i ] = jQuery ( val ) . clone ( ) [ 0 ] ;
265
+ // for disconnected elements, we simply replace
266
+ // with the new content in the set
267
+ self [ i ] = elem ;
274
268
return ;
275
269
}
276
270
277
- jQuery ( this ) . remove ( ) ;
271
+ if ( this . nodeType === 1 || this . nodeType === 11 ) {
272
+ next = this . nextSibling ;
273
+ parent = this . parentNode ;
278
274
279
- if ( next ) {
280
- jQuery ( next ) . before ( val ) ;
281
- } else {
282
- jQuery ( parent ) . append ( val ) ;
275
+ jQuery ( this ) . remove ( ) ;
276
+
277
+ if ( next ) {
278
+ next . parentNode . insertBefore ( elem , next ) ;
279
+ } else {
280
+ parent . appendChild ( elem ) ;
281
+ }
283
282
}
284
283
} ) ;
285
-
286
- return this ;
287
284
} ,
288
285
289
286
detach : function ( selector ) {
@@ -344,7 +341,8 @@ jQuery.fn.extend({
344
341
table && jQuery . nodeName ( this [ i ] , "table" ) ?
345
342
findOrAppend ( this [ i ] , "tbody" ) :
346
343
this [ i ] ,
347
- node
344
+ node ,
345
+ i
348
346
) ;
349
347
}
350
348
0 commit comments