JSFiddle - React, Tailwind, and code Playground
by kboucher
HTML
<table id="mytable">
<thead>
<tr>
<th class="age">age</th>
<th class="sucess">sucess</th>
<th class="weight">weight</th>
</tr>
</thead>
<tbody>
<tr>
<td>20</td>
<td>30%</td>
<td>70.5kg</td>
</tr>
<tr>
<td>30</td>
<td>40%</td>
<td>80.9kg</td>
</tr>
<tr>
<td>13</td>
<td>60%</td>
<td>20.53kg</td>
</tr>
<tr>
<td>44</td>
<td>80.44%</td>
<td>20kg</td>
</tr>
</tbody>
</table>
JavaScript
function getColumnCeiling ( table, colindex ) {
// Must pass table and column index
if ( table === null || colindex === null ) return;
var rows = table.rows,
i = rows.length - 1,
ceil = -1, current;
for ( ; i > -1; i-- ) {
// If this cell does not exist then skip to next
if ( rows[ i ].cells[ colindex ] === undefined ) continue;
current = parseFloat( rows[ i ].cells[ colindex ].innerHTML );
// If this cell does not contain a number then skip to next
if ( current === NaN ) continue;
ceil = current > ceil ? current : ceil;
}
return ceil; // returns -1 if no numbers found to compare
}
var table = document.getElementById( 'mytable' );
alert( getColumnCeiling( table, 1 ) );