Reputation: 103
I have this fiddle and i would like to make it count the number of boxes that are selected. Now it shows the numbers of the boxes.
Any idea how to do it??
$(function() {
$(".selectable").selectable({
filter: "td.cs",
stop: function(){
var result = $("#select-result").empty();
var result2 = $("#result2");
$('.ui-selecting:gt(31)').removeClass("ui-selecting");
if($(".ui-selected").length>90)
{
$(".ui-selected", this).each(function(i,e){
if(i>3)
{
$(this).removeClass("ui-selected");
}
});
return;
}
$(".ui-selected", this).each(function(){
var cabbage = this.id + ', ';
result.append(cabbage);
});
var newInputResult = $('#select-result').text();
newInputResult = newInputResult.substring(0, newInputResult.length - 1);
result2.val(newInputResult);
}
});
});
jsfiddle: http://jsfiddle.net/dw6Hf/44/
Thanks
Upvotes: 2
Views: 50
Reputation: 87073
Just try this withih stop()
:
$(".ui-selected").length
To get all selected div you need to place above code like following:
alert($(".ui-selected").length); // here to place
if ($(".ui-selected").length > 4) {
$(".ui-selected", this).each(function(i, e) {
if (i > 3) {
$(this).removeClass("ui-selected");
}
});
return; // because you've used a return here
}
alert($(".ui-selected").length); // so not to place here
Upvotes: 2
Reputation: 123377
...
stop: function(){
console.log('you selected %d cells', $('.ui-selected').length);
...
Upvotes: 0