Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12906 closed bug (notabug)

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.

Change History (1)

comment:1 Changed 7 years ago by dmethvin

Resolution: notabug
Status: newclosed

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

Note: See TracTickets for help on using tickets.