Opened 14 years ago
Closed 10 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 Changed 14 years ago by
comment:2 Changed 14 years ago by
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 14 years ago by
<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 14 years ago by
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:11 Changed 12 years ago by
Milestone: | 1.3.2 → 1.5 |
---|---|
Status: | new → open |
comment:12 Changed 12 years ago by
Owner: | changed from john to XASD |
---|---|
Status: | open → 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 12 years ago by
Owner: | changed from XASD to john |
---|---|
Priority: | major → high |
Status: | pending → new |
Version: | 1.3.1 → 1.4.4 |
Confirmed in jQuery 0 git (as of c9c9057c4d4097767ca1 / 2010-12-13)
comment:14 Changed 12 years ago by
Status: | new → open |
---|
comment:15 Changed 12 years ago by
Milestone: | → 1.next |
---|---|
Version: | 1.4.4 → 1.6b1 |
comment:16 Changed 12 years ago by
Component: | core → manipulation |
---|
comment:17 Changed 12 years ago by
Priority: | high → low |
---|---|
Summary: | insertAfter → insertAfter, insertBefore, etc do not work when destination is original element |
Confirmed in bug triage, dropping priority to low.
comment:19 Changed 10 years ago by
Owner: | john deleted |
---|---|
Status: | open → assigned |
comment:20 Changed 10 years ago by
Status: | assigned → open |
---|
comment:21 Changed 10 years ago by
I'm going to look at this. Here's a fiddle using the above example:
comment:22 Changed 10 years ago by
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 10 years ago by
Milestone: | 1.next → 1.9 |
---|
comment:26 Changed 10 years ago by
aaaaaaaand another pull request: https://github.com/jquery/jquery/pull/1068
:)
comment:23 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Fix #4087. insertAfter, insertBefore, etc do not work if origin and destination are same element. Close gh-1068.
Changeset: f12611feb43adb2b014eb2183db0713451746aff
Sorry,I mean $("#x").insertAfter("#x") don't know about insertBefore.