jQuery(document).ready(function ($) { $(document).on('click', '#filter-submit', function () { let industry = $('#industry').val(); let region = $('#region').val(); // Detect the Loop Grid after the filter let loopContainer = $(this).closest('.elementor-section').nextAll().find('.elementor-loop-container').first(); if (loopContainer.length === 0) { loopContainer = $('.elementor-loop-container').first(); } $.ajax({ url: '/wp-admin/admin-ajax.php', type: 'POST', data: { action: 'filter_vevents', industry: industry, region: region }, beforeSend: function () { loopContainer.css('opacity', '0.4'); }, success: function (response) { loopContainer.html(response); }, error: function(xhr, status, error){ console.log("AJAX Error:", status, error); }, complete: function () { loopContainer.css('opacity', '1'); } }); }); });