Jump to content

Show / Hide Contents in A Section If I click a Button

Recommended Posts

  • Replies 22
  • Views 852
  • Created
  • Last Reply

Top Posters In This Topic

Here is a quick guide to achieve: Click button - Show hidden section under it.

#1. First, you add a button >> Enter this URL

#load-more

Make sure “Open link in New Tab” is disabled

image.png.624ccfcf4329f6c2d0d30fdfb855dfb2.png

#2. Add a Section under Button. Install this free tool to find ID of section

In my example, we will have ID: 

section[data-section-id="6622374a4dccb83613051b22"]

image.png.9a6898d3214bd163a7fef113194400ea.png

#3. Use this code to Code Injection > FOOTER (or Page Header Injection, page where you use Button/Section)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).ready(function(){  
  // Load More
  $('a[href="#load-more"]').click(function(){
    $(this).remove();
    $('section[data-section-id="6622374a4dccb83613051b22"]').addClass("show");
    $('section:not([data-section-id="6622374a4dccb83613051b22"])').removeClass('show');
    }
  );
});
</script>
<style>
section[data-section-id="6622374a4dccb83613051b22"] {
    display: none;
  transition: all 0.5s;
}
  section.show {
      display: block !important;
    transition: all 0.5s;
  }
</style>

image.png.353b64753311e78eea1e4db3dfc14045.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!)

Link to comment
On 7/16/2024 at 10:12 PM, mggandes said:

In the Squarespace 7.1 version, if I click a button in a section I want to show or see its hidden contents in that section too:

How to hide content and show it when  a button is clicked (example: testimonials (parent testimonial vs professional buttons)

 Like this in this site: https://www.onlinejobs.ph/real-results

Thank you! I got it but whenever I clicked the buttons, they disappeared and showed the same content even if I copied and changed the ID code in  Code Injection of the other button.

 

These are the buttons that look like (1st photo):

 

 

image.thumb.png.c790cf111ddddefa2d6554c80bd2b020.png

 

When I click one of them, it looks like this (2nd photo), the button disappears and the content that appears is for the "Parents" button:

 

image.thumb.png.96b570b33b23e7e4cf0b8acbf5f3307e.png

Link to comment
1 hour ago, mggandes said:

Thank you! I got it but whenever I clicked the buttons, they disappeared and showed the same content even if I copied and changed the ID code in  Code Injection of the other button.

 

These are the buttons that look like (1st photo):

 

 

image.thumb.png.c790cf111ddddefa2d6554c80bd2b020.png

 

When I click one of them, it looks like this (2nd photo), the button disappears and the content that appears is for the "Parents" button:

 

image.thumb.png.96b570b33b23e7e4cf0b8acbf5f3307e.png

The idea that came to my mind is having 2 button elements and 2 below sections (hidden in default).

Using JavaScript to hide the right section. It is noticed that javascript is only available in business plan (or above)

Press 👍  or mark my comment as solution if you find my sharing useful

🆒 Squarespace pinchzoom lightbox plugin (affiliate link)

👁‍🗨 360 degree photo viewer (affiliate link)

Link to comment
On 7/19/2024 at 10:02 PM, mggandes said:

Thank you! I got it but whenever I clicked the buttons, they disappeared and showed the same content even if I copied and changed the ID code in  Code Injection of the other button.

 

These are the buttons that look like (1st photo):

 

 

image.thumb.png.c790cf111ddddefa2d6554c80bd2b020.png

 

When I click one of them, it looks like this (2nd photo), the button disappears and the content that appears is for the "Parents" button:

 

image.thumb.png.96b570b33b23e7e4cf0b8acbf5f3307e.png

@tuanphan

Link to comment

I only see just one section below the button section. 

I describe the following concept to make sure that it  meets your requirement:

1. By default, it should show a section below these buttons and one button is active, right? (The active button can be set up with another color/ less transparent...

2. when we click on the next button > hide the default section and show another section

3. clicking the button will show the appropriate section

image.thumb.png.067b82e5cc203b69ee938fe8a483af43.png

Press 👍  or mark my comment as solution if you find my sharing useful

🆒 Squarespace pinchzoom lightbox plugin (affiliate link)

👁‍🗨 360 degree photo viewer (affiliate link)

Link to comment
21 hours ago, HoaLT said:

I only see just one section below the button section. 

I describe the following concept to make sure that it  meets your requirement:

1. By default, it should show a section below these buttons and one button is active, right? (The active button can be set up with another color/ less transparent...

2. when we click on the next button > hide the default section and show another section

3. clicking the button will show the appropriate section

image.thumb.png.067b82e5cc203b69ee938fe8a483af43.png

Hello! That is what it looked like when I followed @tuanphan 's suggestion that is why you only see just one section (buttons) 

You got it (see my side notes in bold and capitalized for each number below):

1. By default, it should show a section below these buttons and one button is active, right? (The active button can be set up with another color/ less transparent...

Yes, by default it should show a section (we want both buttons to remain the same color)

2. when we click on the next button > hide the default section and show another section

Correct but the other button (button of the default section) must still be visible so that when someone clicks it, they will  go back to the default section

3. clicking the button will show the appropriate section

Correct.

 

Thank you

Link to comment
On 7/25/2024 at 8:45 PM, mggandes said:

Hello! That is what it looked like when I followed @tuanphan 's suggestion that is why you only see just one section (buttons) 

You got it (see my side notes in bold and capitalized for each number below):

1. By default, it should show a section below these buttons and one button is active, right? (The active button can be set up with another color/ less transparent...

Yes, by default it should show a section (we want both buttons to remain the same color)

2. when we click on the next button > hide the default section and show another section

Correct but the other button (button of the default section) must still be visible so that when someone clicks it, they will  go back to the default section

3. clicking the button will show the appropriate section

Correct.

 

Thank you

My approach for 1 button only. With 2 or more buttons, follow this new guide

 

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!)

Link to comment
  • 2 weeks later...
21 hours ago, mggandes said:

Thank you @tuanphan. But the code didn't work. 

Here's the link page where I used the code:

https://memorystrategy.squarespace.com/config/pages/website-tools/code-injection

 

Thanks as always 🙂

/config is url in edit mode, we can't access it.

You can click Arrow on top right of page >> it should show real url in browser address bar

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!)

Link to comment
  • 2 weeks later...
On 9/2/2024 at 8:19 PM, mggandes said:

 Yes. I added the code block in each section when I started doing this.

Code Block 1.png

Code Block 2.png

I think you added to another page because I don't see any Code Blocks on Homepage Page

https://memorystrategy.squarespace.com/

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!)

Link to comment
21 hours ago, mggandes said:

Hi @tuanphan, I just followed the underlined step below and my understanding is the code block will be added to the sections I made. 

I didn't see any step that I needed to add the code block to homepage page 😞

 

please help.

image.thumb.png.a9656a0895f8a65e293b7bc7d980ae37.png

But, on page you shared, I don't see any Code Blocks. Which page you added Code Block? Can share link to that page?

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!)

Link to comment

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.