Skip to main content

Bug Tracker

Side navigation

#13907 closed bug (notabug)

Opened May 17, 2013 06:33PM UTC

Closed May 20, 2013 02:31PM UTC

Last modified May 20, 2013 03:52PM UTC

jQuery 2.0.0 breaks jQuery-ui sortable when items are removed and re-added to the sortable

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.0
Keywords: Cc: scott_gonzalez
Blocked by: Blocking:

Our application uses jQuery UI Sortable and removes elements from the sortable container and re-adds them as part of our render process. With jQuery 1.9.1, this works fine - here is a demonstration using the sortable demo and jQuery 1.9 in jsfiddle:

With jQuery 2.0.0, the first drag after the remove/re-add fails, and subsequent drags succeed. It seems as though other handlers are affected, as well:

The changeset that breaks this is the rewrite of data.js at

It seems like there is something new and undesirable happening with remove and event handlers, and that the effects will probably not be confined to sortables.

Attachments (0)
Change History (5)

Changed May 17, 2013 08:12PM UTC by dmethvin comment:1

cc: → scott_gonzalez

When you .remove() elements from the document it destroys all data and events attached. Seems likely that an initialized sortable has stuff that shouldn't be removed. When I use .detach() the example seems to work fine.

I'd be curious as to why the behavior changed but first I'd like to know if this example is valid or not. Scott do you want to weigh in?

Changed May 20, 2013 01:49PM UTC by anonymous comment:2

But the mousedown handler is on the container, not the elements within the container, and that's what appears to not be triggered on the first drag.

Changed May 20, 2013 02:13PM UTC by scottgonzalez comment:3

_comment0: This is a valid use. I've reduced the fiddle:

This is a valid use. I've reduced the fiddle and added a call to sortable's .refresh() method:

Changed May 20, 2013 02:31PM UTC by scottgonzalez comment:4

resolution: → notabug
status: newclosed

My reduced test case was missing an .end() for the .appendTo(). This is working fine when calling sortable( "refresh" ):

Changed May 20, 2013 03:52PM UTC by anonymous comment:5

Ah, okay, so the fact that this worked without needing a call to 'refresh' prior to jQuery 2.0.0 would fall into the 'happened to work' rather than the 'supposed to work' category.