Build jQuery UI Sortable - Default functionality in JavaScript

Description

The following code shows how to build jQuery UI Sortable - Default functionality.

Example


<!-- Revised from demo code on http://jqueryui.com/ -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Sortable - Default functionality</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<!--from   ww  w  . j  av  a 2s. c  o m-->
<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() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
});
</script>
</head>
<body>

<ul id="sortable">
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 1</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 2</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 3</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 4</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 5</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 6</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 7</li>
</ul>

<div class="demo-description">
<p>
Enable a group of DOM elements to be sortable. Click on and drag an
element to a new spot within the list, and the other items will adjust to
fit. By default, sortable items share <code>draggable</code> properties.
</p>
</div>
</body>
</html>

Click to view the demo

The code above generates the following result.

Build jQuery UI Sortable - Default functionality in JavaScript
Home »
  Javascript Tutorial »
    jQuery UI »
      Sortable
Javascript Tutorial Sortable
Build jQuery UI Sortable - Connect lists in...
Build jQuery UI Sortable - Connect lists wi...
Build jQuery UI Sortable - Default function...
Build jQuery UI Sortable - Delay start in J...
Build jQuery UI Sortable - Display as grid ...
Build jQuery UI Sortable - Drop placeholder...
Build jQuery UI Sortable - Handle empty lis...
Build jQuery UI Sortable - Include / exclud...
Build jQuery UI Sortable - Portlets in Java...
Handle Sortable update event in JavaScript
Set up Placehoder, helper for sortable in J...
Set up Sortable with place holder in JavaSc...