Bug Tracker

Ticket #13233 (closed bug: fixed)

Opened 18 months ago

Last modified 17 months ago

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:
Blocking: Blocked by:

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

comment:1 follow-up: ↓ 5 Changed 18 months ago by 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.

Last edited 18 months ago by dmethvin (previous) (diff)

comment:2 Changed 18 months 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 18 months 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 18 months 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 18 months ago by gibson042

  • Owner set to gibson042
  • Status changed from new to assigned
  • Milestone changed from None to 1.9.1

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 18 months ago by dmethvin (previous) (diff)

comment:7 Changed 18 months ago by Richard Gibson

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: 6b1b0a26b4d485b4d9f334286efed5dfe33e3f3f

comment:8 Changed 18 months 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 18 months ago by timmywil

#13280 is a duplicate of this ticket.

comment:10 Changed 17 months ago by dmethvin

  • Priority changed from undecided to low
  • Component changed from unfiled to manipulation
Note: See TracTickets for help on using tickets.