Handle Selectable selecting and unselecting events in JavaScript

Description

The following code shows how to handle Selectable selecting and unselecting events.

Example


<!-- www . ja v  a  2  s  .c  o 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').selectable({
selecting: function(e, ui) {
$(ui.selecting).addClass('tmpSelected');
},
unselecting: function(e, ui) {
$(ui.unselecting).removeClass('tmpSelected');
}
});
}
);
</script>
<style type='text/css'>
ul {
list-style: none;

}
li {
background: gold;

}
li.tmpSelected {
background: yellow;
}
</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 Selectable selecting and unselecting events in JavaScript
Home »
  Javascript Tutorial »
    jQuery UI »
      Selectable
Javascript Tutorial Selectable
Build jQuery UI Selectable - Default functi...
Build jQuery UI Selectable - Display as gri...
Build jQuery UI Selectable - Serialize in J...
Handle Selectable events: selected, unselec...
Handle Selectable selecting and unselecting...