jQuery Tutorial: Guide to build a custom and simple accordion

jQuery Custom and Simple Accordions

jQuery Custom and Simple Accordions

Guide to Build Custom and Simple Accordion

You have seen the sites with some good accordions. Here I am gonna tell you how to build a simple accordion. What is Accordion? Accordion are the special type of tab type UI element. You can use them to create sidebar menus or for creating interactive pages.

First I want to tell you some benefits of building your own Accordions for your site. So you can…

  1. You can make it as much as small code according to your needs so that the website loading time can be reduced.
  2. You can use it in your way.
  3. You can style it in your way.
  4. You can experiment on it.

So to build a simple and custom jQuery accordion follow some easy steps.

First we will have a set of html elements that will become the backbone to our accordion.

Here is the CSS we gonna use for styling of above code.

Now we will work on JavaScript code to make it work like accordion.

The above code works fine if the CSS only is changed. If the element structure needs to be changed; some parallel changes has to be made in the JavaScript.

This is the simplest code to make the accordion.

If you made something innovative and creative using the above code; share your experiences with us through comments.

And stay tuned for more creative tutorial for web design and development by subscribing to us.

Demo  Download

2 thoughts on “jQuery Tutorial: Guide to build a custom and simple accordion

    1. Pankaj Patel Post author

      To add a + button image before the accordion heads, you can add spans and set their backgrounds as images of the +/- button.
      <div class='item'><span></span>Item 3</div>
      <div class='item-data' >
      <div>
      This is the content for Accordion 3
      </div>
      </div>

      And in CSS

      .item span{
      display:inline-block;
      width: 30px;
      height:30px;
      background:url(/* URL to the Plus/Minus Image of width and height 30px */);
      margin:2px;
      }

      And when the Click event occurs on the accordion Head; you can change the image to -/+ image as required.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">


Recommend on Google