Sort divs in jQuery based on attribute ‘data-sort’?

Use this function var result = $(‘div’).sort(function (a, b) { var contentA =parseInt( $(a).data(‘sort’)); var contentB =parseInt( $(b).data(‘sort’)); return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0; }); $(‘#mylist’).html(result); You can call this function just after adding new divs. If you want to preserve javascript events within the divs, DO … Read more

jQuery UI Sortable, then write order into a database

The jQuery UI sortable feature includes a serialize method to do this. It’s quite simple, really. Here’s a quick example that sends the data to the specified URL as soon as an element has changes position. $(‘#element’).sortable({ axis: ‘y’, update: function (event, ui) { var data = $(this).sortable(‘serialize’); // POST to server using $.post or … Read more