Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Making an Accordion Control?

blakemckenna

PowerPoster
Joined
Jan 22, 2004
Messages
4,928
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

Freelancer
Joined
Jun 12, 2008
Messages
7,647
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. :)

:wave:
 

Sherin

New member
Joined
Jul 19, 2019
Messages
32
You try this query of making an accordian:
Code:
<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

New member
Joined
Jul 19, 2019
Messages
32
You try this query of making an accordian:
Code:
<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

PowerPoster
Joined
Jan 22, 2004
Messages
4,928
tr333...I used the example from the link you provided and made modifications! Works great! Thanks!
 
Top