I have this script
$('table#preview td.price').each(function(){ var price = parseInt($(this).html()); var total; if(price == ''){ price = 0; } total += price; alert(total); });
What he does is get a column with the price of the class, and then, presumably, everything will add it.
However, all I get from this code is NaN. I do not understand what is wrong with the code.
Pay attention to the script if (price == '') . I did this because initially there is no content in the table.
Edit: here is html
<table> <tr> <th>Name</th> <th>Price</th> </tr> <tr> <td>pen</td> <td class="price>6</td> <td>paper</td> <td class="price>8</td> </tr> </table>
source share