I have this bit of script that runs when I click a button. It reads an element on the page (In this case, with the class ".product-sku" and sends the innerText off to a PHP script that queries a database, etc. and returns a content block.
<script type="text/javascript">
jQuery(function($){
$(document).ready(function(){
$("#btnFindStore").click(function(){
sku_no = $(".product-sku").get(0).innerText;
$.post(
'DealerLinks.php',
{ sku: sku_no },
function( data ){ $('#output').replaceWith( data ); });
$('#altStores').modal('show');
});
});
});
The problem is other elements on the page (size options) are changing the data displayed in the .product-sku
element (red shape near bottom of image) but once the above bit of script fires when button "B" is clicked, the .innerText
does not change from the value that was read in the first time the .click()
was fired.
In other words, even though the text displayed in the browser changes, the value of .innerText
does not update and is not returned as the value of the variable when the function is triggered. It will return the correct value, but only once...after it has returned the value and the modal popover is closed, subsequent .click()
s will return the value from the first time the .click()
fired.
How can I get the "real" current value displayed in the .product-sku
element when the .click()
is fired instead of the "old" innerText()
? value?