<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Sortable - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js">
</script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js">
</script>
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
#sortable li span { position: absolute; margin-left: -1.3em; }
</style>
<script>
$(function () {
var rang = JSON.parse(localStorage.getItem('rang')) || [],
li = $("#sortable li"),
arr = [];
for (var i = 0; i < rang.length; i++) {
arr.push(li[rang[i] - 1])
}
rang.length && $(arr)
.appendTo($("#sortable")) && $(".out")
.text(rang);;
$("#sortable")
.sortable({
stop: function (event, ui) {
rang = [];
$("#sortable li")
.each(function (indx, element) {
rang.push(1 + li.index(element) + " ");
});
$(".out")
.text(rang);
localStorage.setItem('rang', JSON.stringify(rang));
}
});
$("#sortable")
.disableSelection();
});
</script>
</head>
<body>
<div class="out">
1 ,2 ,3 ,4 ,5 ,6 ,7
</div>
<ul id="sortable">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
<li class="ui-state-default">Item 6</li>
<li class="ui-state-default">Item 7</li>
</ul>
</body>
</html>