Handle Sortable update event in JavaScript

Description

The following code shows how to handle Sortable update event.

Example


<!-- www  .  ja  v a  2 s .co  m-->


<html>
<head>
<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" />

<script type='text/javascript'>
$(document).ready(
function() {
$('ul').sortable({
placeholder: 'tmpPlaceholder',
helper: function(e, element) {
return $(element).clone().addClass('tmpHelper');
},
update : function(e, ui) {
alert("updated");
}
});
}
);
</script>
<style type='text/css'>
ul {
list-style: none;
}
li.tmpPlaceholder {
height: 22px;
}
</style>
</head>
<body>
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul>
</body>
</html>

Click to view the demo

The code above generates the following result.

Handle Sortable update event 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...