I’m trying to use a script to make only one toggle open at a time on a website page built with Elementor. I am using three toggle widgets in different places on the same page.
I have tried adding the script in different locations and also tried to test it with different browsers but no luck. The script runs without any error but none of the toggles are opening. I already did all the steps of checking the script location, browser developer console and jQuery loading and I also tried to switch to a default WordPress theme. The problem persists.
My script is as follows:
<script>
jQuery(document).ready(function($) {
$('.elementor-tab-title').on('click', function() {
$('.elementor-tab-title').not(this).removeClass('elementor-active')
.attr('aria-expanded', 'false')
.attr('tabindex', '-1')
.attr('aria-selected', 'false');
$(this).addClass('elementor-active')
.attr('aria-expanded', 'true')
.attr('tabindex', '0')
.attr('aria-selected', 'true');
});
});
</script>
It is important to note that in this particular case, I am not using the accordion widget that is provided by Elementor, since it has the first element opened by default on page load.
2
Answers
Essential Addons for Elementor plugin has an accordion widget that keeps all accordions closed. You could try that and disable all the other widgets if don’t need them.
try this instead