Skip to main content

Bug Tracker

Side navigation

#12906 closed bug (notabug)

Opened November 16, 2012 08:58AM UTC

Closed November 16, 2012 01:25PM UTC

wrapAll returns 'this' instead of 'wrap'

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:
Description

In the 'wrapAll' function:

if ( this[0] ) {

The elements to wrap the target around

var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);

if ( this[0].parentNode ) {

wrap.insertBefore( this[0] );

}

wrap.map(function() {

var elem = this;

while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {

elem = elem.firstChild;

}

return elem;

}).append( this );

The bug is here: you've wrapped 'this', and should return 'wrap',

// but you'll fall through and return 'this' instead.

}

return this;

Here's some simple JS code that exposes the bug:

$(document).ready(function() {

var s = document.createElement('span');

s.textContent = 'foo';

$('body').append($(s).wrapAll('<div/>'));

s.textContent = $('body')[0].innerHTML;

});

The page should display:

<div><span>foo</span></div>

Instead, it shows:

<span>foo</span>

The span 's' is not wrapped in a div.

Attachments (0)
Change History (1)

Changed November 16, 2012 01:25PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed
"This method returns the original set of elements for chaining purposes." -- http://api.jquery.com/wrap/