Calculating Subtotals

Calculating Subtotals

I've used jQuery on and off for a couple of years but never enough to fully understand all the features. In the past I've used it to (say) sum up a column of inputs (on blur) and put the sum into a span as a total at the bottom of the column.

My challenge this time is that I've got to do subtotals. And I'm stuck. Hopefully the html below is self-explanatory. The html is dynamic but I have full control of it so I could add indexes or extra attributes etc. The number of inputs and subtotals is dynamic/variable.

Any help gratefully received.
  1. <table>
  2. <tr>
  3. <td><input class="number" /></td>
  4. </tr>
  5. <tr>
  6. <td><input class="number" /></td>
  7. </tr>
  8. <tr>
  9. <td><span class="subtotal" /></td>
  10. </tr>
  11. <tr>
  12. <td><input class="number" /></td>
  13. </tr>
  14. <tr>
  15. <td><input class="number" /></td>
  16. </tr>
  17. <tr>
  18. <td><input class="number" /></td>
  19. </tr>
  20. <tr>
  21. <td><span class="subtotal" /></td>
  22. </tr>
  23. <tr>
  24. <td><span class="total" /></td>
  25. </tr>
  26. </table>