# Other Languages > jQuery >  Making an Accordion Control?

## blakemckenna

I'm using JQuery to create an Accordion control. The problem that I'm having is that when I run my webapp, 1 section of the Accordion control is open. I have a total of 4 sections (<div>'s) but everytime I run it, the 1st <div> is always open. I'm using it as a Sidebar menu control and want all the sections to be closed by default. How can this be done?

Thanks,

----------


## akhileshbc

hmm... without seeing the code or a demo of it, I won't be able to say any solutions. I believe, others would also be like me.  :Smilie: 

 :wave:

----------


## tr333

Are you using a third-party jQuery plugin for this (eg. jQuery UI Accordion)?  Any chance of putting an test/example up on http://jsfiddle.net/?

----------


## blakemckenna

I'll see what I can do...

----------


## Sherin

You try this query of making an accordian:


```
<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.display === "block") {
      panel.style.display = "none";
    } else {
      panel.style.display = "block";
    }
  });
}
</script>
```

----------


## Sherin

You try this query of making an accordian:


```
<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.display === "block") {
      panel.style.display = "none";
    } else {
      panel.style.display = "block";
    }
  });
}
</script>
```

----------


## blakemckenna

tr333...I used the example from the link you provided and made modifications! Works great! Thanks!

----------

