Jump to content

Show more/Hide button on long testimonial text on a carousel section

Recommended Posts

Posted

Yes, you can definitely achieve this with a bit of JavaScript and CSS. Here’s a simple approach:

  1. HTML Structure: Wrap your testimonial content in a <div> and include a "show more" button<div

class="testimonial">

    <p class="testimonial-text">This is the first paragraph of the testimonial. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    <p class="testimonial-more" style="display: none;">This is the rest of the testimonial that will be hidden initially.</p>
    <button class="show-more-btn">Show More</button>
</div>

 

CSS: Style the testimonial as needed. The hidden text is controlled by the display property.

 
.testimonial {
    margin: 20px;
    padding: 10px;
    border: 1px solid #ccc;
}

This will ensure that only the first paragraph is visible initially, with a button to reveal or hide the rest. You can adapt this code to fit your website's design.

If you're looking for more advanced solutions or implementation, feel free to check out resources on my site www.itcrew.in for web development insights!


 
Posted

You try this code to Website Tools > Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
  $(document).ready(function() {
  const $textElement = $(".list-item-content__title");
  const tpfullText = $textElement.text().trim();
  const maxLength = 300;
  if (tpfullText.length > maxLength) {
    const truncatedText = tpfullText.substring(0, maxLength) + "...";
    $textElement.text(truncatedText);
    $textElement.after('<a href="#" class="show-more">Show more</a>');
    $(".show-more").on("click", function(e) {
      e.preventDefault();
      $textElement.text(tpfullText);
      $(this).remove();
    });
  }
});
</script>
<style>
  a.show-more {
    display: block;
    text-align: center;
    margin-top: 10px;
}
</style>

Result

image.thumb.png.9a3f3bca24246c5b38a10ea5fb374803.png

and when click show more

image.thumb.png.ae5c7870a9349ca74247efe3da51cba6.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!)

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.