Bug Tracker

Opened 9 years ago

Closed 5 years ago

#4087 closed bug (fixed)

insertAfter, insertBefore, etc do not work when destination is original element

Reported by: XASD Owned by:
Priority: low Milestone: 1.9
Component: manipulation Version: 1.6b1
Keywords: Cc:
Blocked by: Blocking:

Description

If you do $("#x").insertBefore("#x") element removed entirely from DOM.It seems somehow related to using dom fragments. Version 1.2.6 of jquery work as expected(preserve element on the same place)+it has "reverse" parameter for domManip() used in "after" method,but 1.3.1 does not have one.Is there logical error here?

Thanks.

Change History (23)

comment:1 in reply to:  description Changed 9 years ago by XASD

Sorry,I mean $("#x").insertAfter("#x") don't know about insertBefore.

comment:2 Changed 9 years ago by dmethvin

Owner: set to john

I see what you mean about the documentFragment stuff. Since jQuery.domManip passes in a fragment, jQuery.clean moves #x to the fragment. Later when it gets to the callback in jQuery.after, the original parentNode is gone.

So how did you come up with this case? Is there some more complex code where you end up trying to insert a node after itself?

comment:3 Changed 9 years ago by XASD

<ul id="m">
	<li class="hl">
		<div>c1</div>
		h1
	</li>
	<li>
		<div>c2</div>
		h2
	</li>
</ul>

$("#m div").insertAfter("#m li:first-child div:last-child");//combine in 1

Thanks.

comment:4 Changed 8 years ago by XASD

1.3.2 still not resolved.

Regards.

comment:5 Changed 8 years ago by katbailey

Just wanted to report that this same issue is causing a problem in Drupal's tabledrag functionality, though in our case it's insertBefore - here's a link to the issue on drupal.org: http://drupal.org/node/350275

comment:10 in reply to:  description Changed 7 years ago by XASD

JQuery 1.4.2 bug is still there.

comment:11 Changed 7 years ago by dmethvin

Milestone: 1.3.21.5
Status: newopen

comment:12 Changed 7 years ago by snover

Owner: changed from john to XASD
Status: openpending

Could you please confirm this bug still exists using the jQuery 0 GIT version of jQuery on jsFiddle? If it does not, please provide a link to the testcase.

comment:13 Changed 7 years ago by jitter

Owner: changed from XASD to john
Priority: majorhigh
Status: pendingnew
Version: 1.3.11.4.4

Confirmed in jQuery 0 git (as of c9c9057c4d4097767ca1 / 2010-12-13)

test case

comment:14 Changed 7 years ago by jitter

Status: newopen

comment:15 Changed 6 years ago by timmywil

Milestone: 1.next
Version: 1.4.41.6b1

comment:16 Changed 6 years ago by timmywil

Component: coremanipulation

comment:17 Changed 6 years ago by ajpiano

Priority: highlow
Summary: insertAfterinsertAfter, insertBefore, etc do not work when destination is original element

Confirmed in bug triage, dropping priority to low.

comment:18 Changed 6 years ago by john

#7639 is a duplicate of this ticket.

comment:19 Changed 5 years ago by mikesherov

Owner: john deleted
Status: openassigned

comment:20 Changed 5 years ago by mikesherov

Status: assignedopen

comment:21 Changed 5 years ago by pbramos

I'm going to look at this. Here's a fiddle using the above example:

http://jsfiddle.net/pbramos/gZ7vB/

comment:22 Changed 5 years ago by pbramos

I've got a fix for this that is passing my unit tests. I need to expand my tests a bit to cover all the cases.

comment:25 Changed 5 years ago by gibson042

Milestone: 1.next1.9

comment:26 Changed 5 years ago by pbramos

aaaaaaaand another pull request: https://github.com/jquery/jquery/pull/1068

:)

comment:23 Changed 5 years ago by Paul Ramos

Resolution: fixed
Status: openclosed

Fix #4087. insertAfter, insertBefore, etc do not work if origin and destination are same element. Close gh-1068.

Changeset: f12611feb43adb2b014eb2183db0713451746aff

Note: See TracTickets for help on using tickets.