Hello:
I'm having a problem designing a faq page. I want to use an accordion style list of faq's and responses. No secret, the code is from W3Schools which I want to customize later. It works fine, but not when I try to use it in 4 variants. It'll work in 2 out of 4! Variant widths are 1200px, 960px, 480px, and 320px. All I did was copy the placeholder from the 1st variant to the rest and adjust the width accordingly. The questions (FAQ's) will display, but when I click on one of them, the accordion does not open to show the answer. I'll provide the code below. Any insights would be appreciated. Thanks.
___________________
CSS:
<style>
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
}
/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active, .accordion:hover {
background-color: #ccc;
}
/* Style the accordion panel. Note: hidden by default */
.panel {
padding: 0 18px;
background-color: white;
display: none;
overflow: hidden;
}
</style>
___________________
HTML:
<button class="accordion">Section 1</button>
<div class="panel">
<p>Response 1...</p>
</div>
<button class="accordion">Section 2</button>
<div class="panel">
<p>Response 2...</p>
</div>
<button class="accordion">Section 3</button>
<div class="panel">
<p>Response 3...</p>
</div>
___________________
javascript:
<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>
__________________
Bookmarks