Hide long Product Description with Read More

Tourist
5 0 3

I've taken a good look and tried to implement code from this thread https://ecommerce.shopify.com/c/ecommerce-design/t/hide-long-product-description-482305

but for the life of me I can't get it to work.

Any Help would be much appreciated

 

I've used the following code

<!––Just above </body> tag on theme.liquid ––>

{% if template == "product" %} 
<script type="text/javascript">
jQuery(document).ready(function($)
                             {
        //   $('.fulltext').hide();
		
        $('.readmore').insertAfter( '.product-description' );

        $('.readmore').click(function (event) {
          event.preventDefault();
          var description = document.querySelector('.product-description');
          console.log(description.style.height)
          if (description.style.height === ''){
            description.style.height = 'auto';
          } else if (description.style.height === 'auto'){
            description.style.height = '';
          }
          else{
            description.style.height = '92px';
          }

          $(this).text($(this).text() == 'Read less...' ? 'Read more...' : 'Read less...');
        });
      });
</script>
{% endif %}  


<!––On product-template.liquid ––>

 <div class="product-collapes">
            <div class="product-description rte" itemprop="description">
              {{ product.description }}
            </div>
            <a class="readmore" href="#">Read more...</a>
          </div>


<!––on theme.scss.liquid ––>

.product-description {
  height:200px;
  overflow: hidden;
 }

Any help would be greatly appreciated.

a link to a relevant product page is here

https://www.gomusicgear.com/collections/audio-interface/products/jgk

password: prahgh

1 Like
Shopify Partner
156 4 14

Hi Francis,
Its because of jQuery not defined error.
Add jQuery scripttag before 

jQuery(document).ready(function($)
1 Like
Tourist
5 0 3

Sorted. forgot to include CDN

script

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

2 Likes
Highlighted
New Member
1 0 1

thanks, bro it's  working  :)

1 Like
New Member
2 0 1

Thanks for the code it's really helpful ...)

1 Like