Ticket #1296 (closed feature: fixed)
new method - innerWrap , does wrap on an elements children
| Reported by: | wjessup | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.2 |
| Component: | core | Version: | 1.1.4 |
| Keywords: | Cc: | ||
| Needs: | Review |
Description (last modified by brandon) (diff)
<div>
<span></span> <span></span>
</div>
$('div').innerWrap("<p></p>");
#=>
<div>
<p>
<span></span> <span></span>
</p>
</div>
jquery.js #=> ln 142
//backwards compatibility for wrap
wrap: function(){
return outerWrap();
},
outerWrap: function() {
// The elements to wrap the target around var a = jQuery.clean(arguments);
// Wrap each of the matched elements individually return this.each(function(){
// Clone the structure that we're using to wrap var b = a[0].cloneNode(true);
// Insert it before the element to be wrapped this.parentNode.insertBefore( b, this );
// Find the deepest point in the wrap structure while ( b.firstChild )
b = b.firstChild;
// Move the matched element to within the wrap structure b.appendChild( this );
});
},
innerWrap: function() {
// The elements to wrap the target around var a = jQuery.clean(arguments);
// Wrap each of the matched elements individually return this.each(function(){
// Clone the structure that we're using to wrap var b = a[0].cloneNode(true);
// Insert it before the element to be wrapped var c = $(this).children(); $(this).children().remove(); this.appendChild(b); $(this).children().prepend(c);
});
},
