<div class="product__description--long"> <h5></h5> <p></p> <p></p> <p></p> <p></p> <h5></h5> <p></p> <p></p> <p></p> <h5></h5> <p></p> </div> <script> $(document).ready(function(){ var desTitles = $('.product__description--long h5'); for(var i= 1; i<=desTitles.length; i++) { var wrapSelector = $('.product__description--long h5:nth-of-type('+i+')').nextUntil('.product__description--long h5:nth-of-type('+(i+1)+')'); wrapSelector.wrapAll("<div class='accordion-description__text'></div>") var checkTitle = $('.product__description--long h5:nth-of-type('+i+')'); checkTitle.addClass('accordion-description__title') if(checkTitle.text() == '') { checkTitle.css('display','none'); } } $('.product__description--long h5').click(function(){ $(this).toggleClass('active'); $(this).next().toggleClass('active'); }); }); </script>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter