JSFiddle - React, Tailwind, and code Playground

by Amandeep Singh

HTML

<dl class="accordion">
            <dt class="title">
                <p>Accordion 1</p>
             </dt>
            <dd>
                <p>Some text for the accordion here...</p>
            </dd>
            <dt class="title">
                <p>Accordion 2</p>
             </dt>
            <dd>
                <p>Some text for the accordion here...</p>
            </dd>
<dt class="title">
                <p>Accordion 3</p>
             </dt>
            <dd>
                <p>Some text for the accordion here...</p>
            </dd>
<dt class="title">
                <p>Accordion 4</p>
               </dt>
                <dd>
                <p>Some text for the accordion here...</p>
            </dd>
</dl>

JavaScript

(function($) {
var allPanels = $('.accordion > dd').hide();
    $('.accordion > dd:first-of-type').show();
    $('.accordion > dt:first-of-type').addClass('accordion-active');
  jQuery('.accordion > dt').on('click', function() {
      $this = $(this);
  $target = $this.next(); 
  if(!$this.hasClass('accordion-active')){
      $this.parent().children('dd').slideUp();

      jQuery('.accordion > dt').removeClass('accordion-active');
      $this.addClass('accordion-active');
      $target.addClass('active').slideDown();
  }    else {
  
      jQuery('.accordion > dt').removeClass('accordion-active');
      $this.parent().children('dd').slideUp();
  }
return false;
  });

})(jQuery);