Ticket #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: | ||
| 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 4 years ago by XASD
comment:2 Changed 4 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 4 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:5 Changed 4 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 3 years ago by XASD
JQuery 1.4.2 bug is still there.
comment:11 Changed 3 years ago by dmethvin
- Status changed from new to open
- Milestone changed from 1.3.2 to 1.5
comment:12 Changed 3 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 3 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)
comment:15 Changed 2 years ago by timmywil
- Version changed from 1.4.4 to 1.6b1
- Milestone set to 1.next
comment:17 Changed 2 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 2 years ago by john
#7639 is a duplicate of this ticket.
comment:19 Changed 10 months ago by mikesherov
- Owner john deleted
- Status changed from open to assigned
comment:21 Changed 7 months ago by pbramos
I'm going to look at this. Here's a fiddle using the above example:
comment:22 Changed 7 months 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 7 months ago by pbramos
pull request: https://github.com/jquery/jquery/pull/1033
comment:24 Changed 7 months ago by pbramos
new pull request: https://github.com/jquery/jquery/pull/1047
comment:26 Changed 6 months ago by pbramos
aaaaaaaand another pull request: https://github.com/jquery/jquery/pull/1068
:)
comment:23 Changed 6 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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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