I have a two section on my page, one for processor and the other one is Ram, I am fetching prices from database using ajax how can i add all those prices which are in the span class="total"?
<td>
<span class="multTotalRam total" id="show_productRam" readonly value="">650.00</span>
</td>
<td>
<span class="multTotalPro total" id="show_productPro" readonly value="">1050.00</span>
</td>
Just loop through class and add all value one by one.
var sum = 0;
$('.total').each(function() {
sum += parseFloat($(this).text()); //
});
console.log('sum', sum);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<td>
<span class="multTotalRam total" id="show_productRam" readonly value="">650.00</span>
</td>
<td>
<span class="multTotalPro total" id="show_productPro" readonly value="">1050.00</span>
</td>
</div>
Not tried / tested but perhaps you could try the following
let total=0;
document.querySelectorAll('span.total').forEach(span=>{
total+=parseFloat( span.innerText )
})
alert( total )