Jump to content

Make accordion menu script compatible with Ajax loading

Recommended Posts

Posted

Site URL: https://brine-demo.squarespace.com/

How would you rewrite this script so it works despite the Ajax loading on the Brine template? Right now it only works if you refresh the page.

<script> $(document).ready(function(){
$('.markdown-block .sqs-block-content h3').css('cursor','pointer');
$(".markdown-block .sqs-block-content h3").nextUntil("h3").slideToggle();
$(".markdown-block .sqs-block-content h3").click(function()
{$(this).nextUntil("h3").slideToggle();}); }); </script>
  • Replies 1
  • Views 711
  • Created
  • Last Reply
Posted
6 hours ago, siaeva said:

Site URL: https://brine-demo.squarespace.com/

How would you rewrite this script so it works despite the Ajax loading on the Brine template? Right now it only works if you refresh the page.

<script> $(document).ready(function(){
$('.markdown-block .sqs-block-content h3').css('cursor','pointer');
$(".markdown-block .sqs-block-content h3").nextUntil("h3").slideToggle();
$(".markdown-block .sqs-block-content h3").click(function()
{$(this).nextUntil("h3").slideToggle();}); }); </script>

try

<script> 
  $(document).ready(function(){
		accordionTrigger();
  }); 
window.addEventListener('mercury:load', accordionTrigger);
function accordionTrigger(){
   	$('.markdown-block .sqs-block-content h3').css('cursor','pointer');
    $(".markdown-block .sqs-block-content h3").nextUntil("h3").slideToggle();
    $(".markdown-block .sqs-block-content h3").click(function()
    {$(this).nextUntil("h3").slideToggle();}); 
}
  </script>

 

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Pinch/Zoom images, videos - PDFs Lightbox - ...) </>  🗓️ Delivery Date Picker (Date picker form field)
Gallery block 7.1 workaround </> 🤖 Ask me anything

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.