jQuery UI Sortable Position

Jiew Meng picture Jiew Meng · Jun 5, 2010 · Viewed 106.7k times · Source

How do I track what position an element is when its position in a sortable list changes?

Answer

Nick Craver picture Nick Craver · Jun 6, 2010

You can use the ui object provided to the events, specifically you want the stop event, the ui.item property and .index(), like this:

$("#sortable").sortable({
    stop: function(event, ui) {
        alert("New position: " + ui.item.index());
    }
});

You can see a working demo here, remember the .index() value is zero-based, so you may want to +1 for display purposes.