wrapAll
wrapAll: function( html ) {
// <summary>
// Wrap all matched elements with a structure of other elements.
// This wrapping process is most useful for injecting additional
// stucture into a document, without ruining the original semantic
// qualities of a document.
// This works by going through the first element
// provided and finding the deepest ancestor element within its
// structure - it is that element that will en-wrap everything else.
// This does not work with elements that contain text. Any necessary text
// must be added after the wrapping is done.
// Part of DOM/Manipulation
// </summary>
// <returns type="jQuery" />
// <param name="html" type="Element">
// A DOM element that will be wrapped around the target.
// </param>
if ( this[0] ) {
// The elements to wrap the target around
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;
},