Jump to content

[Share] Click accordion title - Change image on right

Recommended Posts

Posted

If you have an accordion block like this. You want when clicking on each accordion item >> change image on right.

image.png.1c3c13ef72d7505ffbcd4230d4bbd933.png

You can follow these steps

#1. First, add an Accordion Block and 3 Image Blocks on Right.

image.png.fdcd9153baae8c2f78a2eec0f70441e1.png

#2. Find ID of 4 Blocks.

In my example, it is: 

  • Accordion Block: #block-yui_3_17_2_1_1732105464935_11135
  • Image 01: #block-yui_3_17_2_1_1732180734113_17966
  • Image 02: #block-2c21a42595311ecfc9af
  • Image 03: #block-290c4e18907fa00a0391

image.png.8cf1b59fcb156fb9754179333100bf37.png

#3. Use this code to Code Injection - Footer (or Page Header Injection)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
    const blocks = [
        "#block-yui_3_17_2_1_1732180734113_17966",
        "#block-2c21a42595311ecfc9af",
        "#block-290c4e18907fa00a0391"
    ];
    $(blocks.join(", ")).hide();
    $(blocks[0]).show();
    $("li.accordion-item").on("click", function () {
        const index = $(this).index();
        $(blocks.join(", ")).hide();
        $(blocks[index]).show();
    });
});
</script>

image.png.f8ba1bafd24f8cc517ad970528757f0d.png

#4. Result

image.png.7445c3ab88e9fec8dee0db3fadcef4c5.png

image.png.6ea9e6997bad6964205801988f0736cb.png

image.png.b3d0c91b12d7f8bbbd8a14e94ac56206.png

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • Replies 0
  • Views 85
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

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.