Jump to content

[Share] Click button - show different newsletter

Recommended Posts

Posted (edited)

If you have any problems or can't do this on your site, you can comment below or message me. I can help easier.

Suppose we need to create something like this, when users click on each button >> show corresponding newsletter block.

image.png.a9b9a5fc9b1c75cd302fd97e8e9263ed.png

 

#1. First, add 2 Button Blocks and 2 Newsletter Blocks

click-button-show-newsletter-01-min.png.20fa1ed17a9696c7d7f6d8909c204c60.png

#2. Edit 2 Button Blocks, and use these URLs:

  • #forbuyer
  • #forseller

and make sure the option “Open Link in New Tab” is disabled.

image.png.b09bb8a78fb04cdd1c0476e941c4e9d2.png

image.png.92ee9a7cf81655222758773419c29a10.png

#3. Install this free tool to find ID of 2 Newsletter Blocks

https://chromewebstore.google.com/detail/squarespace-id-finder/igjamfnifnkmecjidfbdipieoaeghcff

In my example, we will have

  • Newsletter 1: #block-7410df8c50a7724d4fcc
  • Newsletter 2: #block-3b3a7f22b741c66555b9

image.png.3628cf78bed3ce98fb9b7669d81ae96a.png

#4. Use this code to Code Injection > Footer (or Page Header Code Injection, page where you use 2 Newsletter Blocks)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  // For Buyer 
  $("#block-7410df8c50a7724d4fcc").closest('.fe-block').addClass('forbuyer show');
    $('a[href="#forbuyer"]').addClass('active-button');
  // For Seller
$("#block-3b3a7f22b741c66555b9").closest('.fe-block').addClass('forseller');
  
  // For Buyer 
  $('a[href="#forbuyer"]').click(function(){
    $(".forbuyer").addClass("show");
    $('.fe-block:not(.forbuyer)').removeClass('show');
    $(this).addClass('active-button');
    $('a:not([href="#forbuyer"])').removeClass('active-button');
    }
  );
// For Seller
 $('a[href="#forseller"]').click(function(){
   $(".forseller").addClass("show");
    $('.fe-block:not(.forseller)').removeClass('show');
    $(this).addClass('active-button');
    $('a:not([href="#forseller"])').removeClass('active-button')
    }
  );
});
</script>
<style>
.forbuyer .newsletter-block, .forseller .newsletter-block {
    display: none;
}
  .show .newsletter-block {
      display: block !important;
  }
  .show {
      z-index: 999999 !important;
  }
  .active-button {
  background-color: green !important;
  }
</style>

#5. Adjust some style

If you want to change Button Style to Checkbox like this

image.png.a9b9a5fc9b1c75cd302fd97e8e9263ed.png

Use this code to Website Tools > Custom CSS

a[href="#forbuyer"]:before, a[href="#forseller"]:before {
    content: "\f0c8";
    font-family: "Font Awesome 6 Free";
    font-weight: bold;
    font-size: 20px;
    color: #000 !important;
	 margin-right: 5px;
    font-weight: 400;
}
a[href="#forbuyer"], a[href="#forseller"] {
    background-color: transparent !important;
    color: #000 !important;
}
.active-button:before {
    content: "\f14a" !important;
}

 

Edited by tuanphan
fix js code

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
  • Replies 0
  • Views 259
  • 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.