JQuery UI Sortable Position

jqueryjquery-uijquery-ui-sortable

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

Best Answer

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.