samedi 13 novembre 2021

Sum filtered items/images

I have a filter with checkboxes using Shuffle.js, just after filtering want to count/sum filtered items using filtered items .length(), and update a div with this value. For the reason I don't get the calculation is wrong. Here what Im trying :

 var _checkbox = $(".buttons input");
     _checkbox.on('change', function(){
     
        var countThis = $(this).val(),
            total = 0;
        $('input:checkbox:checked').each(function(){ 
            var shuffleItems = $('.image[data-gallery="'+countThis+'"]').length;
            total += isNaN(parseInt(shuffleItems)) ? 0 : parseInt(shuffleItems);
            //total += shuffleItems;
           // total = parseInt(total) + (parseInt(shuffleItems) || 0);
        });

       console.log(total);
      $('.nr-filtered').text(total);
    });

here a pen of more details : (https://codepen.io/testeristesting/pen/oNeaZYm)

Thanks,




Aucun commentaire:

Enregistrer un commentaire