Sum value of elements inside of a div using jquery

前端 未结 1 1796
清酒与你
清酒与你 2021-02-09 04:51

I\'m doing a sorting of a set of users, I have 4 groupings like so (2 shown):

相关标签:
1条回答
  • 2021-02-09 05:19

    Something like this would insert a div containing Total: # after each group:

    $(".groupWrapper").each(function() {
      var total = 0;
      $(this).find(".skill").each(function() {
        total += parseInt($(this).text());
      });
      $(this).append($("<div></div>").text('Total: ' + total));
    });
    

    You can adjust the markup, etc...just adjust it based on whatever you want to do with the total.

    0 讨论(0)
提交回复
热议问题