How to append the id of li elements in the jQuery UI selectable multiples

223 Views Asked by At

Okay, so I'm trying to integrate the jQuery UI plugin selectable (grid), and I like how it posts the selected indexes back. Here is what I would like to do:

$(function() {
    $( "#selectable" ).selectable({
        stop: function() {
            var result = $( "#select-result" ).empty();
            $( ".ui-selected").each(function() {
                 var index = $( "#selectable li" ).attr('id');
                                   // But I want the ids of all the selected elements,
                                   // but the id of the first is just getting copied on my site!
                result.append( "#" + ( index + 1 ) );
            });
        }
    });
});
1

There are 1 best solutions below

3
samura On BEST ANSWER

Try:

$(function() {
    $( "#selectable" ).selectable({
        stop: function() {
            var result = $( "#select-result" ).empty();
            $( ".ui-selected").each(function() {
                 var index = $( this ).attr('id'); 
                result.append( "#" + ( index + 1 ) );
            });
        }
    });
});