Demo: https://tuanphan-demo01.squarespace.com/click-text-show-accordion?noredirect
Password: abc
Suppose you have 2 Texts.
You want: when users click on each Text >> Show Accordion.
#1. First, you add a Text Block with some text/url.
Make sure the option “Open link in new tab” is disabled
- #accordion01
- #accordion02
and 2 Accordion Blocks below.
#2. Install Squarespace ID Finder to find the ID of Text and Accordion.
In my example, we will have:
- Text Block: #block-yui_3_17_2_1_1710553606022_10552
- Accordion 01: #block-yui_3_17_2_1_1710553606022_12405
- Accordion 02: #block-yui_3_17_2_1_1710553606022_12950
#3. Use code to Code Injection – Footer (or Page Header Code Injection)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script> <script> $(document).ready(function(){ // Accordion 01 $("#block-yui_3_17_2_1_1710553606022_12405").closest('.fe-block').addClass('accordion01'); // Accordion 02 $("#block-yui_3_17_2_1_1710553606022_12950").closest('.fe-block').addClass('accordion02'); // Accordion 01 $('a[href="#accordion01"]').click(function(){ $(".accordion01").addClass("show"); $('.fe-block:not(.accordion01)').removeClass('show'); } ); // Accordion 02 $('a[href="#accordion02"]').click(function(){ $(".accordion02").addClass("show"); $('.fe-block:not(.accordion02)').removeClass('show'); } ); }); </script> <style> .accordion01 .accordion-block, .accordion02 .accordion-block { display: none; } .show .accordion-block { display: block !important; } .show { z-index: 999999 !important; } </style>
#4. Explain code