using jQuery to assign an html value, but after that jQuery returns old value, why?
<p>Am using a jQUery AJAX call to assign the value of a table cell.  The cell is a subtotal, mysubtotalB. That works great as you can clearly see the results.  However at the end of the success function, included is a call to another jQuery function.  The next function is supposed to get the new value just assigned to mysubtotalB and add it to Total A/table cell mysubtotalA.  </p>

<p>The part that is odd, is that even after the new value is assigned on screen to mysubtotalB, the value returned via a jQuery statement is 0, or the original value.  Playing with it for a while I noticed that if I ran a second AJAX call and assigned another value to mysubtotalB, the I got the previous value.  That is, the value returned by the jQuery assignment was always one value old. Guessing maybe the DOM did not update on the first call or maybe it has to do with the order of execution, even if the total is assigned before the call is made to the second function.   </p>

<p>Does anyone know why this is and what to do about it.</p>

<pre><code>&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Total A&lt;/th&gt;
&lt;td id='mysubtotalA'&gt;0.00&lt;/td&gt;&lt;!-- default state when page loads --&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;Total B&lt;/th&gt;
&lt;td id='mysubtotalB'&gt;0.00&lt;td&gt;&lt;!-- default state when page loads --&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;Grand total&lt;/th&gt;
&lt;td id='mygrandtotal'&gt;0.00&lt;td&gt;&lt;!-- default state when page loads --&gt;
&lt;/tr&gt;
&lt;/table&gt;

$.ajax({
...
success: function(returned){
$('#mysubtotalB').html(returned);//works fine returned value now on screen in mysubtotalB
}
)};

&lt;script&gt;
...
var theReturnedValue = $('#mysubtotalB').html();
alert('theReturnedValue');// outputs "0" the first default value
&lt;/script&gt;
</code></pre>
