html - Add number from divs with jQuery -
html - Add number from divs with jQuery -
i have these divs.
<div class="prices">11.99</div> <div class="prices">1.99</div> <div id="price">99</div>
how can add together numbers divs?
the final result must 11.99+1.99+99=112.98
thank you.
you can this.
class="snippet-code-js lang-js prettyprint-override">var controls = $("div"); var sum = 0; (var = 0; < controls.length; i++) { var ct = parsefloat($(controls[i]).text()); sum += ct; } alert(sum);
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="prices">11.99</div> <div class="prices">1.99</div> <div id="price">99</div>
jquery html add
Comments
Post a Comment