Demo: https://tuanphan-demo01.squarespace.com/click-button-map-v2?noredirect
Password: abc
Suppose you have 2 buttons and 2 Map Blocks.
And you want: when clicking on the Button, Map will appear below it.
You can follow these steps:
#1. First, add 2 Button Blocks and 2 Map Blocks
#2. Edit 2 Button Blocks, and use these URLs:
- #map01
- #map02
and make sure the option “Open Link in New Tab” is disabled.
#3. Install Squarespace ID Finder to find the ID of all blocks.
In my example, we will have:
- Button 01: #block-yui_3_17_2_1_1711157606982_5498
- Button 02: #block-yui_3_17_2_1_1711157606982_5972
- Map 01: #block-yui_3_17_2_1_1711157606982_6428
- Map 02: #block-yui_3_17_2_1_1711157606982_6874
#4. 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(){ $("#block-yui_3_17_2_1_1711157606982_6428").addClass("show"); // Map 01 $('#block-yui_3_17_2_1_1711157606982_5498 a[href="#map01"]').click(function(){ $("#block-yui_3_17_2_1_1711157606982_6428").addClass("show"); $('div:not(#block-yui_3_17_2_1_1711157606982_6428)').removeClass('show'); } ); // Map 02 $('#block-yui_3_17_2_1_1711157606982_5972 a[href="#map02"]').click(function(){ $("#block-yui_3_17_2_1_1711157606982_6874").addClass("show"); $('div:not(#block-yui_3_17_2_1_1711157606982_6874)').removeClass('show'); } ); }); </script> <style> #block-yui_3_17_2_1_1711157606982_6428, #block-yui_3_17_2_1_1711157606982_6874 { opacity: 0; transition: all 0.1s ease; } .show { opacity: 1 !important; transition: all 0.1s ease; } </style>
#5. Explain code