Skip to main content

Bug Tracker

Side navigation

#3270 closed bug (worksforme)

Opened August 20, 2008 05:25PM UTC

Closed November 17, 2010 01:34AM UTC

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:
Description

For example:

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

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 (0.6 KB) - added by dmethvin January 19, 2009 01:35AM UTC.
Change History (3)

Changed January 19, 2009 01:07AM UTC by dmethvin comment:1

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 March 02, 2009 12:48AM UTC by dmethvin comment:2

owner: → flesler

Changed November 17, 2010 01:34AM UTC by dmethvin comment:3

resolution: → worksforme
status: newclosed