Here is simple example of Jquery UI Sortable,how it can be used with div's.
First include libraries in your html:
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>` <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>`<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>``
Html for making sortable:
<div id="target">
<div style="cursor: move;" class="entity">
<div class="digit"><span>1</span><tab /> First Item </div>
</div>
<div style="cursor: move;" class="entity">
<div class="digit"><span>2</span> Second Item</div>
</div>
<div style="cursor: move;" class="entity">
<div class="digit"><span>3</span> Third Item</div>
</div>
<div style="cursor: move;" class="entity">
<div class="digit"><span>4</span> Fourth Item</div>
</div>
<div style="cursor: move;" class="entity">
<div class="digit"><span>5</span> Fifth Item</div>
</div>
</div>
Here is the sortable function:
$(document).ready(function() {
$('#target').sortable({
items:'div.entity', //the div which we want to make sortable
scroll:true, //If set to true, the page
//scrolls when coming to an edge.
update:function(event,ui){ renumber(); } //This event is triggered when the user
//stopped sorting and the DOM position has changed.
});
});
renuber() is called from the Sortable update event handler callback:
function renumber()
{
$('.digit span').each(function(index,element) {
$(element).html(index+1);
});
}