Each Loop In Jquery
<script>
$.each( obj, function( key, value ) {
alert( key + ": " + value );
});
</script>
<script>
$.each( [ "a", "b", "c" ], function( i, l ){
alert( "Index #" + i + ": " + l );
});
</script>
Run Each Loop in Table data
<table id="mainTable" border="2" width="100%">
<thead >
<th>Id</th>
<th>Title</th>
<th>Amount</th>
</thead>
<tbody>
<tr>
<td>01</td>
<td>title 1</td>
<td>199</td>
</tr>
<tr>
<td>01</td>
<td>title 2</td>
<td>450</td>
</tr>
<tr>
<td>01</td>
<td>title 3</td>
<td>230</td>
</tr>
</tbody>
</table>
<span id="total-value"></span>
<script type="text/javascript">
var total = 0;
$('#mainTable > tbody > tr ').each(function(key, value)
{
total = total + parseInt(value.cells[2].innerText);
});
$('#total-value').text(total);
</script>
0 Comments