Jump to content

JavaScript code isn't working

Recommended Posts

Posted

Hi all, trying to hide the accordion block and make it appear after clicking on a button. Here is the code that I use, Could anyone look and say where is the pain point here?

<SCRIPT>
function ShowAndHide() {
    var x = document.getElementById('section[data-section-id="64d15395c579ed75d02954dc"]');
    if (x.style.display == 'none') {
        x.style.display = 'block';
    } else {
        x.style.display = 'none';
    }
}
</SCRIPT>

<BUTTON ONCLICK="ShowAndHide()">Strategy</BUTTON>

<DIV ID="section[data-section-id="64d15395c579ed75d02954dc"]" STYLE="display:none">Text to be shown and hidden</DIV>

 

Thank you!

  • Replies 1
  • Views 813
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted

Are you married to the button as your method of toggling?

I have some code that uses sections to hide/show other sections. Check the demo.

If you still want a button, let us know and we may be able to help.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

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.