Selectable
jQuery UI Selectable
Overview
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.
Dependencies
- UI Core
- UI Widget
- UI Mouse
Example
$("#selectable").selectable();
<!DOCTYPE html> <html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <style type="text/css"> #selectable .ui-selecting { background: silver; } #selectable .ui-selected { background: gray; } </style> <script> $(document).ready(function() { $("#selectable").selectable(); }); </script> </head> <body style="font-size:62.5%;"> <ul id="selectable"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> <li>Item 5</li> </ul> </body> </html>
Options
Events
Methods
-
destroy
- Signature:
- .selectable( "destroy" )
Remove the selectable functionality completely. This will return the element back to its pre-init state.
-
disable
- Signature:
- .selectable( "disable" )
Disable the selectable.
-
enable
- Signature:
- .selectable( "enable" )
Enable the selectable.
-
option
- Signature:
- .selectable( "option" , optionName , [value] )
Get or set any selectable option. If no value is specified, will act as a getter.
-
option
- Signature:
- .selectable( "option" , options )
Set multiple selectable options at once by providing an options object.
-
widget
- Signature:
- .selectable( "widget" )
Returns the .ui-selectable element.
-
refresh
- Signature:
- .selectable( "refresh" )
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.
Theming
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 jquery.ui.selectable.css stylesheet that can be modified. These classes are highlighed in bold below.
Sample markup with jQuery UI CSS Framework classes
<ul class="ui-selectable"><li class="ui-selectee"></li>
<li class="ui-selectee"></li>
<li class="ui-selectee"></li>
</ul>
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>.