Minimalist Accordion Plugin For Vanilla JavaScript

Category: Accordion , Javascript | May 14, 2018
Author:pinceladasdaweb
Views Total:852 views
Official Page:Go to website
Last Update:May 14, 2018
License:MIT

Preview:

Minimalist Accordion Plugin For Vanilla JavaScript

Description:

A dead simple accordion plugin written in pure vanilla JavaScript that allows you to toggle the visibility of content panels on click.

How to use it:

Import the JavaScript file accordion.min.js into the html document.

<script src="assets/js/accordion.js"></script>

The basic HTML structure for the accordion.

<div id="accordion" class="accordion">
  <h2 id="demo1">Demo 1</h2>
  <div>
    <ul>
      <li>Text here</li>
      <li>Text here</li>
      <li>Text here</li>
    </ul>
  </div>
  <h2 id="demo2">Demo 2</h2>
  <div>
    <ul>
      <li>Text here</li>
      <li>Text here</li>
      <li>Text here</li>
    </ul>
  </div>
  <h2 id="demo3">Demo 3</h2>
  <div>
    <ul>
      <li>Text here</li>
      <li>Text here</li>
      <li>Text here</li>
    </ul>
  </div>
</div>

Done. Style the accordion in the CSS as per your needs.

#accordion {
  /* styles here */
}
#accordion .toggle-active {
  /* styles here */
}
.closed {
  display: none;
}

You Might Be Interested In:


Leave a Reply