The jQuery UI Selectable plugin allows for elements to be selected by dragging a box (sometimes called a lasso) with the mouse over the elements. Also, elements can be selected by click or drag while holding the Ctrl/Meta key, allowing for multiple (non-contiguous) selections.
$("#selectable").selectable();
<!DOCTYPE html> <html> <head> <link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" /> <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.selectable.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#selectable").selectable(); }); </script> </head> <body style="font-size:62.5%;"> <div id="selectable"></div> </body> </html>
This event is triggered at the end of the select operation, on each element added to the selection.
selected
event as an init option.
$('.selector').selectable({
selected: function(event, ui) { ... }
});
selected
event by type: selected
.
$('.selector').bind('selected', function(event, ui) {
...
});
This event is triggered during the select operation, on each element added to the selection.
selecting
event as an init option.
$('.selector').selectable({
selecting: function(event, ui) { ... }
});
selecting
event by type: selecting
.
$('.selector').bind('selecting', function(event, ui) {
...
});
This event is triggered at the beginning of the select operation.
start
event as an init option.
$('.selector').selectable({
start: function(event, ui) { ... }
});
start
event by type: selectablestart
.
$('.selector').bind('selectablestart', function(event, ui) {
...
});
This event is triggered at the end of the select operation.
stop
event as an init option.
$('.selector').selectable({
stop: function(event, ui) { ... }
});
stop
event by type: selectablestop
.
$('.selector').bind('selectablestop', function(event, ui) {
...
});
This event is triggered at the end of the select operation, on each element removed from the selection.
unselected
event as an init option.
$('.selector').selectable({
unselected: function(event, ui) { ... }
});
unselected
event by type: unselected
.
$('.selector').bind('unselected', function(event, ui) {
...
});
This event is triggered during the select operation, on each element removed from the selection.
unselecting
event as an init option.
$('.selector').selectable({
unselecting: function(event, ui) { ... }
});
unselecting
event by type: unselecting
.
$('.selector').bind('unselecting', function(event, ui) {
...
});
Remove the selectable functionality completely. This will return the element back to its pre-init state.
Disable the selectable.
Enable the selectable.
Get or set any selectable option. If no value is specified, will act as a getter.
Refresh the position and size of each selectee element. This method can be used to manually recalculate the position and size of each selectee element. Very useful if autoRefresh is set to false.
Toggles the state of selectable functionality. This method either enables or disables selecting based on the current state.
The jQuery UI Selectable plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
If a deeper level of customization is needed, there are widget-specific classes referenced within the ui.selectable.css stylesheet that can be modified. These classes are highlighed in bold below.
Note: This is a sample of markup generated by the selectable plugin, not markup you should use to create a selectable. The only markup needed for that is
<ul>
<li></li>
<li></li>
<li></li>
</ul>.