JSFiddle - React, Tailwind, and code Playground
HTML
<table id="example" class="display table" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td class="details-control"></td>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td class="details-control"></td>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<tr>
<td class="details-control"></td>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
</tr>
</tbody>
</table>
<div class="total">
Total: <span id="spn-total">0</span>
</div>
CSS
table.table {
border-collapse: collapse;
}
table.table th, .total {
padding: 6px;
background-color: #ccc;
}
table.table td {
padding: 2px 6px;
border: solid 1px #c9c8c4;
}
.total {
margin-top: 10px;
display: inline-block;
float: right;
}
JavaScript
(function ($) {
//DOM ready
$(function() {
var last_col, values, total;
//get last <td> in all rows
last_col = $("#example tbody tr td:last-child");
//get the values in all <td> as an array of numbers
values = $.map(last_col.get(), function (td) {
return +$(td).text().replace(/[\$\,\s]/g, "") || 0;
});
console.log(values);
//sum the values
total = values.reduce(function (prev, current) {
return prev + current;
}, 0 /*starts prev*/);
$("#spn-total").text(total);
});
}(jQuery));