Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1133261

    FarBlueIR
    Participant

    Morning,

    I have read from a previous post from this forum on how to create collapsible sections, which can be expanded/hidden when pressing a button (https://community.theme.co/forums/topic/collapsible-complete-section-accordion-style-javascript-jquery-trouble/), but I was wondering if there was a way to automatically close a section which is already opened, if a new one is opened. At the moment, once you expand a section it will remain open until you click on the same button to close it.

    For one of the sections, I have the following examples for the ‘ID’ and ‘Class’ sections:

    – ID: one.
    – Class: section-expandable

    Then, under the ‘Custom JS’ settings, I have the following:

    jQuery(document).ready(function($){
    $(‘#one’).slideToggle(0);
    $(‘#one-trigger-button’).click(function(e){
    $(‘#one’).slideToggle( “slow” );
    e.preventDefault();
    });
    });

    Kind regards,
    FBIR

    #1133500

    Paul R
    Moderator

    Hi,

    You can try this code.

    
    jQuery(document).ready(function($){
    	$('#one').slideToggle(0);
        $('#one-trigger-button').on('touchend click', function(){
           $(".section-expandable").not("#one").slideUp();
           $('#one').slideToggle( "slow" );
        });
    });
    

    Hope that helps

    #1133530

    FarBlueIR
    Participant

    Hi Paul,

    Many thanks for your help. I’ve just tried the code from your post and it now works perfectly.

    Kind regards,
    FBIR

    #1133774

    Rupok
    Member

    You are welcome!

    Glad that it helped. Feel free to let us know if you face any other issue. We’ll be happy to assist you.

    Thanks for using X.

    Cheers!