jquery code stops working after ajax page load.
Initially, when the page loads, 20 products are loaded and this script works, but after switching to another page with products that is loaded with ajax, this code stops working
(function($){
$(document).ready(function(){
$(".variable-item.image-variable-item").on("click", function(){
if($(this).parents('.jet-woo-product-button').length){
let btn = $(this).parents('.jet-woo-product-button').find('.add_to_cart_button');
if(btn.length){
btn.click();
btn.click(function(){
btn.data('clicked', true);
});
setTimeout(function(){
if(btn.data('clicked') != true){
btn.click();
}
btn.data('clicked', false);
}, 500);
}
} else if($(this).parents('.variations_form').find('.single_add_to_cart_button').length){
let btn = $(this).parents('.variations_form').find('.single_add_to_cart_button');
if(btn.length){
setTimeout(function(){
btn.click();
}, 500);
}
}
});
});
})
(jQuery);