Search code examples
jquerydragreorderlist

reorder list elements with mouse jquery


I have floating list elements and I want to make them draggable with mouse and move them to reorder. The structure is as follows:

<ul>
    <li>item1</li>
    <li>item2</li>
    <li>item3</li>
    <li>item4</li>
</ul>

What is the best way to do it?


Solution

  • use jquery UI for this purpose!

    http://jqueryui.com/sortable/

    $(function() {
        $( "ul" ).sortable();
        $( "ul" ).disableSelection();
    });