jquery - JavaScript Calculate total price of items -
please me type total price of selected items. here jsfiddle
<section id="items"> <div class="item">monitor <span class="price">100$</span></div> <div class="item">mouse <span class="price">20$</span></div> <div class="item">keyboard <span class="price">60$</span></div> </section> <section id="basket"> <p>total price:<span class="total_price"></span></p> </section>`
check demo
var total = 0; $("#items").on('click', ".item", function() { $(this).appendto("#basket"); gettotal() }); $("#basket").on('click', ".item", function() { $(this).appendto("#items"); gettotal() }); function gettotal(){ total = 0; $("#basket").find('.price').each(function(i){ total += parseint($(this).text().slice(0,-1)); if(i + 1 === $("#basket").find('.item').length){ $('.total_price').text(total+'$'); } }); }
Comments
Post a Comment