kevinabraham kevinabraham - 1 month ago 6x
HTML Question

How to use jQuery sortable to update div ID's when a user moves an element?

I am using jQuery sortable to allow users to move elements around on a page. Each div element has a unique ID. When the user swaps an element on the page with another I want to also swap those element ID's and alert the new list of ID's order, So I can save this new order to the backend.

I am struggling to get the child element ID's for when the user moves an element. My jQuery so far is:

$(function() {
stop: function(ev, ui) {
var children = $('#sortable').sortable('refreshPositions').children();
alert('Positions: ');
$.each(children, function() {
var drag_id = $('.container').attr("id");

but the alert message is always
. How do I swap the div ID's when the user makes a change and save this to an array and then
this array?



You must set ID for (li) tag . Check Fiddle now