javascript - Push a Value of the Selected List in an Array and Calculate -
here's code @ moment. wanted push or object selected in array.
$('.checkbox-wrapper').delegate('input:checkbox', 'change', function () { //use if want uncheck other checkbox if checkbox checked //$('input').not(this).prop('checked', false); var $lis = $('.list > li').hide(); $('input:checked').each(function () { $lis.filter('#' + $(this).attr('data-stats')).show(); }); console.log($lis.filter('#' + $(this).attr('data-stats'))); var myvals = []; $lis.filter('#' + $(this).attr('data-stats')).map(function () { myvals.push($(this).attr('value')); }); var arr = myvals, total = 0; $.each(arr, function () { total += this; }); $("#total").text(total); console.log(total) }).find('input:checkbox').change();
you doing wrong:
$.each(arr,function(i) { total += arr[i]; });
Comments
Post a Comment