Demo: https://tuanphan-demo01.squarespace.com/click-text-play-audio-v2?noredirect
Password: abc
#1. First, you add a Text Block, with these URLs.
Make sure the option “Open link in new tab” is disabled
- #audio01
- #audio02
and 2 Audio Blocks below
#2. Install Squarespace ID Finder and find the ID of all blocks
In my example, we will have:
- Text Block: #block-yui_3_17_2_1_1711785272442_14562
- Audio 01: #block-yui_3_17_2_1_1711783156414_29403
- Audio 02: #block-yui_3_17_2_1_1711785272442_10678
#3. Use this 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_1711783156414_29403").addClass("show"); // Audio 01 $('#block-yui_3_17_2_1_1711785272442_14562 a[href="#audio01"]').click(function(){ $("#block-yui_3_17_2_1_1711783156414_29403").addClass("show"); $('div:not(#block-yui_3_17_2_1_1711783156414_29403)').removeClass('show'); } ); // Audio 02 $('#block-yui_3_17_2_1_1711785272442_14562 a[href="#audio02"]').click(function(){ $("#block-yui_3_17_2_1_1711785272442_10678").addClass("show"); $('div:not(#block-yui_3_17_2_1_1711785272442_10678)').removeClass('show'); } ); }); </script> <style> #block-yui_3_17_2_1_1711783156414_29403, #block-yui_3_17_2_1_1711785272442_10678 { opacity: 0; transition: all 0.1s ease; } .show { opacity: 1 !important; transition: all 0.1s ease; } </style>
#4. Explain code