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>
The code above generates the following result.