Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vituchon/41b97519d7e9dc77c93ba24af0930160 to your computer and use it in GitHub Desktop.
Save vituchon/41b97519d7e9dc77c93ba24af0930160 to your computer and use it in GitHub Desktop.
function sumTableCells(tableId,cellIndex) {
var table = document.getElementById(tableId);
debugger;
let subTotal = Array.from(table.rows).reduce((total, row) => {
const textContent = row?.cells[cellIndex]?.textContent
return total + textContent ? parseInt(textContent.split(" ")[1].replace(",",".")) : 0
}, 0);
return subTotal
}
sumTableCells("table",5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment