javascript - How can I get the sum of all table rows with a certain class in jQuery? -


how can sum values of table rows countme class in jquery?

html:

<div id="sum">$0</div> <table>     <tr>         <th>id</th> <th>value</th>     </tr>     <tr class="countme">         <td>1</td> <td class="v">$10</td>     </tr>     <tr>         <td>2</td> <td class="v">$20</td>     </tr>     <tr class="countme">         <td>3</td> <td class="v">$10</td>     </tr>     <tr>         <td>4</td> <td class="v">$30</td>     </tr> </table> 

i need #sum $20. how can that?

you can this:

var sum = 0;  $('tr.countme td.v').each(function() {     sum += parsefloat($(this).text().slice(1)); });  $('#sum').text(sum); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -