title: PHP read more read less - Magento 2
body: <p>I made an read more read less script for my Magento 2 webshop. This is used on a category page where there are serval subcategorie blocks to choose, each subcategory has a description with.</p>
  
  <p><p>The problem: if I click read more all the descriptions of the subcategories will expand in stead of only the description of the subcategory I clicked read more</p><p>I am starting to learn PHP and Magento 2 but I can't fix this, does someone know the solution?</p></p>
  
  <pre><code>  &lt;div class="product description product-item-description"&gt;
                                  &lt;div class="more"&gt;
                                  &lt;?php  if ($_subCategory-&gt;getDescription()) {
          $string = strip_tags($_subCategory-&gt;getDescription());
  
          if (strlen($string) &gt; 250) {
              // truncate string
              $stringCut = substr($string, 0, 250);
              $string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... &lt;a href="javascript:void(0);" class="readmore"&gt;Lees meer&lt;/a&gt;';
          }
          echo $string;
          ?&gt;
          &lt;/div&gt;
      &lt;?php
      }else {?&gt;
          &lt;?php /* @escapeNotVerified */ echo $_attributeValue; 
          }
      ?&gt;
      &lt;/div&gt;
  
      &lt;div class="less" style="display:none"&gt;
          &lt;?php echo $_subCategory-&gt;getDescription(); ?&gt;
          &lt;a href="javascript:void(0);" class="readless"&gt;Lees minder&lt;/a&gt;
      &lt;/div&gt;
      &lt;script type="text/javascript"&gt;
          console.log('test');
          require(["jquery"],function($){
              $('.readmore').on("click",function(){
                  $('.less').show();
                  $('.more').hide();
              });
              $('.readless').on("click",function(){
                  $('.less').hide();
                  $('.more').show();
              });
          });
      &lt;/script&gt;
      &lt;/div&gt;
  </code></pre>