Reputation: 20538
I am using jQuery and the widget Selectable to let my user select files to delete. I am appending each selection to a div to be able to see what divs I have selected. I need to comma seperate the values (ids) to be able to use it when saving.
How can I comma seperate? Is there a better way of doing this?
$("#photo_area").selectable({
cancel: 'a',
stop: function() {
var result = $("#selected").empty();
$(".ui-selected", this).each(function() {
var index = $(this).attr('id');
result.append(index);
});
}
});
Upvotes: 1
Views: 205
Reputation: 17617
Not sure what you are after. But you can always use a comma speerated string as a jQuery selector.
$('#myId2, #myId1, #myId3')
..fredrik
Upvotes: 0
Reputation: 342655
There's nothing blatantly wrong with what you already have, but I think the following is a little more concise:
var ids = $(this).find(".ui-selected").map(function() {
return this.id;
}).get().join(",");
Upvotes: 1