Jump to content

Javascript only working on page reload SS 7.0

Recommended Posts

Site URL: https://www.freeformgroup.org/phoenix-rising-1

I have a markdown accordion on my site that only works after the page is reloaded. Is this an ajax problem?

Here is the javascript I'm using that has worked fine on other sites:

<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 h2').css('cursor','pointer');
    $(".markdown-block .sqs-block-content h2").nextUntil("h2").slideToggle();
    $(".markdown-block .sqs-block-content h2").click(function() {$(this).nextUntil("h2").slideToggle();});
    });
    </script>

Link to comment
  • Replies 2
  • Views 1.4k
  • Created
  • Last Reply

Hi DevonLois

Did you try to turn off ajax? I think the issue comes from the script not first again when you navigate to the page via ajax

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
20 minutes ago, DevonLois said:

Site URL: https://www.freeformgroup.org/phoenix-rising-1

I have a markdown accordion on my site that only works after the page is reloaded. Is this an ajax problem?

Here is the javascript I'm using that has worked fine on other sites:

<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 h2').css('cursor','pointer');
    $(".markdown-block .sqs-block-content h2").nextUntil("h2").slideToggle();
    $(".markdown-block .sqs-block-content h2").click(function() {$(this).nextUntil("h2").slideToggle();});
    });
    </script>

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
    $(document).ready(function() {
      window.addEventListener('mercury:load', function() {
      	$('.markdown-block .sqs-block-content h2').css('cursor','pointer');
    	$(".markdown-block .sqs-block-content h2").nextUntil("h2").slideToggle();
    	$(".markdown-block .sqs-block-content h2").click(function() {$(this).nextUntil("h2").slideToggle();});
      });    	
    });
</script>

Reference: https://stackoverflow.com/questions/47509602/squarespace-ajax-loading-do-not-display-custom-code

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

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.