Jump to content

Modify a Markdown Accordion

Recommended Posts

Hello!  

I'm attempting to modify a simple markdown accordion to start in the "open" position. So the entire accordion is expanded on load. Can someone help with this? Thank you! Here's a copy of some code I'm using.

 

 

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>     

    $(document).ready(function(){

    $('.markdown-block .sqs-block-content h3').addClass('ui-closed').css('cursor','pointer');

    $(".markdown-block .sqs-block-content h3").nextUntil("h3").slideToggle();

    $(".markdown-block .sqs-block-content h3").click(function() {  

      $(this).nextUntil("h3").slideToggle();

      $(this).toggleClass('ui-closed ui-open');

      });

    });

      </script>

Link to comment
  • Replies 8
  • Views 420
  • Created
  • Last Reply

Top Posters In This Topic

25 minutes ago, alsmith877 said:

Hello!  

I'm attempting to modify a simple markdown accordion to start in the "open" position. So the entire accordion is expanded on load. Can someone help with this? Thank you! Here's a copy of some code I'm using.

 

 

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>     

    $(document).ready(function(){

    $('.markdown-block .sqs-block-content h3').addClass('ui-closed').css('cursor','pointer');

    $(".markdown-block .sqs-block-content h3").nextUntil("h3").slideToggle();

    $(".markdown-block .sqs-block-content h3").click(function() {  

      $(this).nextUntil("h3").slideToggle();

      $(this).toggleClass('ui-closed ui-open');

      });

    });

      </script>

Can you share URL so I can check it?

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

If you want to set an accordion to open all its items, try the custom script

<script>
  document.addEventListener('DOMContentLoaded', () => {
    const accBl = document.querySelector('#BlockID .accordion-items-container');
    if (accBl) {
      const accItems = accBl.querySelectorAll('.accordion-item');
      accItems.forEach(accItem => {
        accItem.setAttribute('data-is-open', true);
        const dropItem = accItem.querySelector('.accordion-item__dropdown');
        if (dropItem) {
          dropItem.classList.add('accordion-item__dropdown--open');
        }
      })
    }
  })
</script>

Chảng #BlockID with your own one

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

You can use this one #block-9f737c5a8badb8f9361b

Use the following extension to get the one you want: Squarespace ID Finder (google.com)

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

Ok I added in the block ID. I was successful in opening the accordion, but the functionality is disabled. I was hoping to be able to still "open/close" the accordion, just have it load in the open position. 

 

If you're still interested in helping, I'd love more advice! Thanks so much. 

 

 

Link to comment
Posted (edited)
8 hours ago, alsmith877 said:

Ok I added in the block ID. I was successful in opening the accordion, but the functionality is disabled. I was hoping to be able to still "open/close" the accordion, just have it load in the open position. 

 

If you're still interested in helping, I'd love more advice! Thanks so much. 

 

 

My code only works on the accordion block, not the markdown one you use. Do you consider using accordion instead of the markdown block?

Edited by Beyondspace

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment
  • 2 weeks later...

Hello BeyondSpace!

 

My client is opposed to using the native accordion block because entering information into it is slow. Unfortunately, he is adamant about this. Do you have any insight into how I would solve this via the markdown method? You have my continued gratitude. 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.