Skip to main content

Bug Tracker

Side navigation

#1296 closed feature (fixed)

Opened June 15, 2007 06:02AM UTC

Closed August 31, 2007 05:34AM UTC

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

<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);

});

},

Attachments (0)
Change History (2)

Changed June 15, 2007 06:09AM UTC by brandon comment:1

component: ajaxcore
description: \ <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); \ }); \ },<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); \ }); \ },
priority: majorminor
type: bugenhancement

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/

Changed August 31, 2007 05:34AM UTC by john comment:2

milestone: 1.1.31.2
resolution: → fixed
status: newclosed
type: enhancementfeature
version: 1.1.21.1.4

Fixed in SVN rev [3021].