X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcore.js;h=a11ceb430dbc160459d1a9ebc3800b22dfd5b2ff;hb=82958c79ff7604b1854a58cf161e8d6691bed6ac;hp=6c439a5a6c449d6a8a2b91b1bb31aa3895aee523;hpb=0c97178553606c01b999441836e23f9f36c645a3;p=jquery.git diff --git a/src/core.js b/src/core.js index 6c439a5..a11ceb4 100644 --- a/src/core.js +++ b/src/core.js @@ -206,20 +206,22 @@ jQuery.fn = jQuery.prototype = { }, wrapAll: function( html ) { - if ( this[0] ) + if ( this[0] ) { // The elements to wrap the target around - jQuery( html, this[0].ownerDocument ) - .clone() - .insertBefore( this[0] ) - .map(function(){ - var elem = this; - - while ( elem.firstChild ) - elem = elem.firstChild; - - return elem; - }) - .append(this); + var wrap = jQuery( html, this[0].ownerDocument ).clone(); + + if ( this[0].parentNode ) + wrap.insertBefore( this[0] ); + + wrap.map(function(){ + var elem = this; + + while ( elem.firstChild ) + elem = elem.firstChild; + + return elem; + }).append(this); + } return this; },