javascript - Sum TD in TABLE -


<table id="tab" border="1">     <tr>         <td>one</td><td>123</td><td></td><td>32</td>     </tr>     <tr>         <td>two</td><td>52</td><td></td><td>53</td>     </tr>     <tr>         <td>three</td><td>234</td><td></td><td>56</td>     </tr> </table>  $('#tab').click(function(){    sum(); })  function sum(){  //???? } 

how best method sum column second , fourth td , fill in third td each tr?

live: http://jsfiddle.net/byf8c/

function sum(){     $("tr").each(function(){         var sum = parsefloat($(this).find("td:eq(1)").text()) +                    parsefloat($(this).find("td:eq(3)").text());         $(this).find("td:eq(2)").text(sum);     }) } 

here, have fiddle: http://jsfiddle.net/byf8c/10/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -