Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1494287

    Hello,

    On my recipe site, I have several sections with an accordion for each section. How can I have only one toggle open at a time for the whole accordion group? That is, if the user opens a toggle in one accordion, any toggle open in another accordion is closed.

    Thanks!
    Serge

    #1494300

    try in your child-theme functions.php:

    function ava_custom_toggle_behavior(){
    ?>
    <script type="text/javascript">
    (function($) {
        $(window).on('load', function() {
            $('.toggler').on('click', function() {
                var $current = $(this);
                
                // Short delay so Enfold can set its own classes
                setTimeout(function() {
                    if ($current.hasClass('activeTitle')) {
                        // Find all other togglers on the page that are active
                        $('.toggler').not($current).each(function() {
                            if ($(this).hasClass('activeTitle')) {
                                // Simulate click or remove classes manually
                                $(this).trigger('click');
                            }
                        });
                    }
                }, 100);
            });
        });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'ava_custom_toggle_behavior');
    #1494301

    Thanks Guenni007, it did the trick.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.