2

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?

Gavin42
  • 490
  • 8
  • 19
Petefic
  • 657
  • 6
  • 14
  • 31

1 Answers1

2

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
        }    
    }
);
Gavin42
  • 490
  • 8
  • 19
Radai
  • 230
  • 3
  • 8