jsharpe
jsharpe

Reputation: 2665

how do I determine the position of a LI in a jquery sortable list?

After I move (sort) one of my list items I would like to know which position it just got dropped into. I'm pretty sure this is impossible to calculate off of ui.position/offset since I have been able to drop onto the same pixel and have the item go in two different slots, depending on which direction I dragged the element from.

I suppose I can do some traversing and counting after the object is dropped but I was hoping that there was some direct way of getting this piece of info.

Thanks

Upvotes: 1

Views: 2173

Answers (2)

jsharpe
jsharpe

Reputation: 2665

This gets what I need.

ui.item.prevAll().length + 1

Upvotes: 1

Steerpike
Steerpike

Reputation: 17544

I wrote an article for smashing magazine that gets the order of li's for sending through to a backend. You might find the drag and drop/jquery parts of the tutorial useful.

Upvotes: 1

Related Questions