Skip to content

Instantly share code, notes, and snippets.

@awolad
Created February 7, 2018 05:03
Show Gist options
  • Save awolad/3b88393ca825d06604ca130961fc9099 to your computer and use it in GitHub Desktop.
Save awolad/3b88393ca825d06604ca130961fc9099 to your computer and use it in GitHub Desktop.
Get sum of subtotal
function tally(selector, tdClass) {
$(selector).each(function () {
var total = 0,
column = $(this).siblings(selector).andSelf().index(this);
$(this).parents().prevUntil(':has(' + selector + ')').each(function () {
total += parseFloat($('td.'+ tdClass +':eq(' + column + ')', this).html()) || 0;
})
$(this).html('<strong>' + total + '</strong>');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment