Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Make accordion menu script compatible with Ajax loading


siaeva

Question

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>
Link to comment

1 answer to this question

Recommended Posts

  • 0
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>

 

Greeting, it's BaNgan from BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Portfolio hover Replace Link Style
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

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