JSFiddle - React, Tailwind, and code Playground

by lollero

HTML

<div id="mywraper">
      <div>4</div>
      <div>5</div>
	  <div>6</div>
</div>
<div id="total_div">
    Total $<span id="total"></span>
</div>

<button id="updateBtn">Update values</button>

JavaScript

function total() {
    var parentContainer = $('#mywraper'),
        total = 0;

    parentContainer.children().text(function( i, val ) {
        total += parseInt( val );
    });

    $('#total').html( total );
    
}

total();

$('#updateBtn').on("click", function() {

    $('#mywraper').children().text(function( i, val ) {
        return parseInt( val ) + 1;
    });

    total();

});