views:

91

answers:

2

I have an unordered list <ul> with list items <li> which I'd like to be able to "reorder" via dragging. I'm using jQuery. How could I accomplish this? I tried hooking into the click event but I can't get the drag to work right (I want the other <li> elements to move out of the way once I drag an <li> element over a suitable spot so the user can see where it would end up).

Help?

+2  A: 

If you don't need to invent the wheel:

http://jqueryui.com/demos/sortable

jAndy
I looked at this but I couldn't find any example on how to make it work with an unordered list...
Alex
@Alex: that demo infact deals with an unordered list
jAndy
Looks like the SO new answer notification doesn't work on an iPhone. :). +1
David Hoerster
@jAndy: lol, now that you changed the link from draggable to sortable :) Didn't know about sortable before. thanks!
Alex
A: 

Have you considered jQuery UI's droppable/draggable functionality?

Here's a link to a ul demo.

http://jqueryui.com/demos/draggable/#sortable

David Hoerster