How to add html contents taken from an html table?
<p>I have this script</p>

<pre><code>$('table#preview td.price').each(function(){
var price = parseInt($(this).html());
var total;
if(price == ''){
price = 0;
}
total += price;
alert(total);
});
</code></pre>

<p>What it does is get the column that has the class price then supposedly adds it all up. </p>

<p>However, all I get from this code is NaN. I don't get what's wrong with the code.</p>

<p>Please note the script <strong>if(price == '')</strong>. I've done this because initially there are no contents in the table.</p>

<p>Edit: Here the html</p>

<pre><code>    &lt;table&gt;
    &lt;tr&gt;
    &lt;th&gt;Name&lt;/th&gt;
    &lt;th&gt;Price&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td&gt;pen&lt;/td&gt;
    &lt;td class="price&gt;6&lt;/td&gt;
    &lt;td&gt;paper&lt;/td&gt;
    &lt;td class="price&gt;8&lt;/td&gt;    
    &lt;/tr&gt;
    &lt;/table&gt;
</code></pre>
