Bug Tracker

Ticket #4087 (closed bug: fixed)

Opened 6 years ago

Last modified 23 months ago

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

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

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

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

comment:2 Changed 6 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 6 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 6 years ago by XASD

1.3.2 still not resolved.

Regards.

comment:5 Changed 6 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 5 years ago by XASD

JQuery 1.4.2 bug is still there.

comment:11 Changed 4 years ago by dmethvin

  • Status changed from new to open
  • Milestone changed from 1.3.2 to 1.5

comment:12 Changed 4 years ago by snover

  • Owner changed from john to XASD
  • Status changed from open to pending

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 4 years ago by jitter

  • Owner changed from XASD to john
  • Priority changed from major to high
  • Version changed from 1.3.1 to 1.4.4
  • Status changed from pending to new

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

 test case

comment:14 Changed 4 years ago by jitter

  • Status changed from new to open

comment:15 Changed 4 years ago by timmywil

  • Version changed from 1.4.4 to 1.6b1
  • Milestone set to 1.next

comment:16 Changed 4 years ago by timmywil

  • Component changed from core to manipulation

comment:17 Changed 3 years ago by ajpiano

  • Priority changed from high to low
  • Summary changed from insertAfter to insertAfter, insertBefore, etc do not work when destination is original element

Confirmed in bug triage, dropping priority to low.

comment:18 Changed 3 years ago by john

#7639 is a duplicate of this ticket.

comment:19 Changed 2 years ago by mikesherov

  • Owner john deleted
  • Status changed from open to assigned

comment:20 Changed 2 years ago by mikesherov

  • Status changed from assigned to open

comment:21 Changed 2 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 2 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:23 Changed 2 years ago by pbramos

comment:24 Changed 2 years ago by pbramos

comment:25 Changed 2 years ago by gibson042

  • Milestone changed from 1.next to 1.9

comment:26 Changed 23 months ago by pbramos

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

:)

comment:23 Changed 23 months ago by Paul Ramos

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

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.