How can I transfer the CURRENT value of one unit to another?

Good day!

The situation is the following. Online store. And on the shopping basket page go one under one of the blocks with the selected goods. Each has the ability to switch the number and the total amount for this product. At the bottom is calculated by means of php and js total amount of purchases.
I need this sum to transfer to a special unit in the header.

For starters, I tried to track the event when clicking on the zoom in button quantity. We get the following:

$(document).on('click', '.order-item-select-btn', function(e){
 var totalSum = $('.value-total').text();
$('#shpcrtca').text(totalSum);
});


Keep track of the event, assign variable value , and push this value into the appropriate block. BUT
1. The value appears and immediately disappears
2. Shows the sum with -1 step. I.e. if you select three items in there at a clique carried a cost which was for 2 units. Select four units - received at the top 3. Ie bere not the current value , and the value of which was at the time of the committing of a click and not after.

Please tell me how to deal with it
July 2nd 19 at 13:54
1 answer
July 2nd 19 at 13:56
Solution
1. Your bad code elsewhere for specifics throw on JSFiddle
2. Wrap a setTimeout(..., 0)
and thanks for that.. - ashlee.Reichel67 commented on July 2nd 19 at 13:59

Find more questions by tags JavaScriptjQuery