How can I check if only one element was selected when using JQuery UI's selectable()
?
So if I just click on one element and select it, an alert box would show. But if I used the lasso to select multiple items, the alert box would not show.
$('#area').selectable({
selected: function (event, ui)
{
//if number of selected elements=1:
//do something
}
);
How would I do this?
Use the length
property to check the number of items selected:
$('#area').selectable({
selected: function (event, ui) {
if ($('.ui-selected').length === 1) {
//only one selected
}
}
);