I'm facing a dilemma
On my website, I need to capture the value of a span within a modal. The value changes when the modal is opened and reverts to the old value when closed. This particular value represents the cart total in my online store. Whenever I click on the "add product to cart" button, the modal with the updated value appears.
I attempted to achieve this using the following code:
$('.ajax_add_to_cart_button').click(function()
{
if($('#layer_cart').css('display') == 'block')
{
var total_product = $('.ajax_block_products_total').text().replace('€', '').replace(',', '.');
alert(total_product);
}
});
However, this only returned the old value because the modal is not yet opened when the "add to cart" button is clicked, causing it to have a display-none status.
What would be a more suitable event to check if the modal has truly opened? Since there is a slight delay due to an AJAX request to fetch cart details from the server, I am unsure which event timing would be appropriate for capturing the new value.
I initially tried implementing the action on the "add to cart" button's onclick event, but since the modal had not yet opened, it retrieved the outdated value.
Any assistance or suggestions are greatly appreciated.