Opened 16 years ago
Closed 15 years ago
#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: | ||
Blocked by: | Blocking: |
Description (last modified by )
<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);
});
},
Change History (2)
comment:1 Changed 16 years ago by
Component: | ajax → core |
---|---|
Description: | modified (diff) |
Priority: | major → minor |
Type: | bug → enhancement |
comment:2 Changed 15 years ago by
Milestone: | 1.1.3 → 1.2 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Type: | enhancement → feature |
Version: | 1.1.2 → 1.1.4 |
Fixed in SVN rev [3021].
There are several existing innerWrap methods already in use. Here is my recent take on an innerWrap method: http://blog.brandonaaron.net/2007/06/04/jquery-snippets-innerwrap/