Suppose I have the following sortable object:
<ul class="photos ui-sortable">
<li class="photo" data-id="1"></li>
<li class="photo" data-id="2"></li>
<li class="photo" data-id="3"></li>
<li class="photo" data-id="4"></li>
<li class="photo" data-id="5"></li>
<li class="photo" data-id="6"></li>
</ul>
Upon sorting, the data-id attribute of all the items need to be updated with their new positions.
I tried this:
$('.photos').sortable({
stop: function(event, ui){
$(ui.item).attr('data-id', ui.item.index()+1);
}
});
But it only updates the data-id of the item that was moved, and not the others. How can I do this?