Petefic
Petefic

Reputation: 677

JQuery UI Selectable(): Check if only one element is selected

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?

Upvotes: 2

Views: 856

Answers (1)

Radai
Radai

Reputation: 240

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
        }    
    }
);

Upvotes: 2

Related Questions