Bug Tracker

Opened 14 years ago

Closed 12 years ago

#3270 closed bug (worksforme)

jQuery().wrapInner() prepends instead of wrapping when html structure contains text nodes

Reported by: jtate Owned by: flesler
Priority: major Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc:
Blocked by: Blocking:


For example:


would work fine. However

jQuery('p').wrapInner('<strong> </strong>')

will produce html output that looks like:

<p><strong> </strong>INNER TEXT</p>

when it meets a paragraph element with the Text contents of "INNER TEXT".

Attachments (1)

3270.patch (630 bytes) - added by dmethvin 14 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 14 years ago by dmethvin

The problem is this loop in wrapAll:

	while ( elem.firstChild )
		elem = elem.firstChild;

It's trying to find the deepest point in the wrapping nodes to know where to append the nodes in the jQuery object. However, if any of the firstChild nodes in the wrapper are text nodes, it won't work right. I've attached a patch that tries to find the leftmost non-text node.

Changed 14 years ago by dmethvin

Attachment: 3270.patch added

comment:2 Changed 14 years ago by dmethvin

Owner: set to flesler

comment:3 Changed 12 years ago by dmethvin

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.