Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#13233 closed bug (fixed)

Unexpected behavior when iterating over and manipulating detached nodes in jquery 1.9

Reported by: octatone Owned by: gibson042
Priority: low Milestone: 1.9.1
Component: manipulation Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:

Description

I have a convenience method that I use to wrap text elements in a html string in spans. In 1.8.3 and before it has worked as intended. I wanted to upgrade to 1.9.0, but am finding my function breaks and that manipulation on detached nodes and their child elements to not reflect correctly. Child elements seem to not be connected to the original node and any changes are not present on the parent.

I created an example case here:

1.8.3: http://jsfiddle.net/octatone/cAmD5/ 1.9.0: http://jsfiddle.net/octatone/dMYeB/

In 1.8.3 all child text nodes are wrapped in spans. In 1.9 the result is that the html of the node is never changed and subsequently the returned result is not correct.

Change History (10)

comment:1 Changed 11 years ago by dmethvin

You're affected by this change:

http://stage.jquery.com/upgrade-guide/1.9/#after-before-and-replacewith-with-disconnected-nodes

As the guide says, we made this change so that the methods didn't have inconsistent behavior on the stack and set.

Version 0, edited 11 years ago by dmethvin (next)

comment:2 Changed 11 years ago by octatone

So, any guidance on how to change this function to work around this change? How do I get access to the manipulated set?

comment:3 Changed 11 years ago by dmethvin

You could use .map() instead and return a newly created text node with the modifications. There is probably some cleaner way to do this but I haven't wrapped my head around the use case.

comment:4 Changed 11 years ago by octatone

The use case is to preserve html, but wrap text in spans ... basically to make each char clickable. Regardless of it's parent html element. Anchors, divs, etc.

comment:5 in reply to:  1 Changed 11 years ago by gibson042

Milestone: None1.9.1
Owner: set to gibson042
Status: newassigned

Replying to dmethvin:

You're affected by this change:

http://jquery.com/upgrade-guide/1.9/#after-before-and-replacewith-with-disconnected-nodes

As the guide says, we made this change so that the methods didn't have inconsistent behavior on the stack and set.

I thought so too, but it seems like this regression actually stems from a nodeType restriction introduced in https://github.com/jquery/jquery/commit/551c2c9f4ac776b6d53600c452ad40a4b4d6670b.

Last edited 11 years ago by dmethvin (previous) (diff)

comment:7 Changed 11 years ago by Richard Gibson

Resolution: fixed
Status: assignedclosed

Fix #13233: re-allow .replaceWith of text nodes. Close gh-1137.

Changeset: 6b1b0a26b4d485b4d9f334286efed5dfe33e3f3f

comment:8 Changed 11 years ago by Richard Gibson

Fix #13233: re-allow .replaceWith of text nodes. Close gh-1137. (cherry picked from commit 6b1b0a26b4d485b4d9f334286efed5dfe33e3f3f)

Changeset: a96aa9e2709b4ba132b966a0f1a13d0e8eb49b9a

comment:9 Changed 11 years ago by Timmy Willison

#13280 is a duplicate of this ticket.

comment:10 Changed 11 years ago by dmethvin

Component: unfiledmanipulation
Priority: undecidedlow
Note: See TracTickets for help on using tickets.