Making an Accordion Control?
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,
Re: Making an Accordion Control?
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:
Re: Making an Accordion Control?
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/?
Re: Making an Accordion Control?
I'll see what I can do...
Re: Making an Accordion Control?
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>
Re: Making an Accordion Control?
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>
Re: Making an Accordion Control?
tr333...I used the example from the link you provided and made modifications! Works great! Thanks!