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(); 

my js fiddle

you doing wrong:

$.each(arr,function(i) {   total += arr[i]; }); 

fiddle: http://jsfiddle.net/y9xx8qzv/


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -