Yevgeniy Bagackiy Yevgeniy Bagackiy - 2 months ago 15
PHP Question

Counting items inside two droppable objects

I have an accordion and two droppable boxes: box1 and box2. How can I count number of dropped items in both boxes in total. Here is fiddle. I am using

().length
to count but it seems not working, here is code:

$( document.body ).append( $( ".dropClass" ) );
var n = $( ".dropClass" ).length;
$( "span" ).text( "Items Droped: " + n + ".");

Answer

that should work, try to move the following lines

var n = $( ".dropClass" ).length;   
$( "span" ).text( "Items Dropped: " + n + ".");

inside

drop: function(event, ui)

so your final code would be something like:

//add style
$('.ui-droppable').find("li.ui-draggable:contains('" + zz + "')").addClass('bred');
var n = $( ".dropClass" ).length;   
$( "span" ).text( "Items Dropped: " + n + ".");

Try this fiddle.