FAQ accordion main using HTML, CSS, and a bit of JavaScript.

Solution retrospective
I hope you like this solution, and I would appreciate your comments with observations and constructive criticism to continue improving my code.
Please log in to post a comment
Log in with GitHubCommunity feedback
- P@danielmrz-dev
Hello @ozkrTr!
Your project looks great!
I noticed that if you click on a question that's showing its answer, it doesn't close until you click on another question.
I had the same problem but mine worked with this js function:
function mostrar(pergunta, check, source, height) { if (checkbox[check].checked) { imagens[pergunta].src = source; answers[pergunta].style.height = height; } else { imagens[pergunta].src = 'assets/images/icon-plus.svg'; answers[pergunta].style.height = '0'; } }
What this funtion does is:
- If the question is closed, it opens when you click. And if your question is open, it closes when you click. But I didn't use
display: none
anddisplay: block
. I usedheight: 0
andheight: 90px
. It has the same effect, because if the height is 0, the answer does not appear.
I'm still a JavaScript student, but that worked really fine for me. If you want to take a look at my solution, here it is > link.
I hope it helps!
Other than this little detail, you did an excelent job!
Marked as helpful - If the question is closed, it opens when you click. And if your question is open, it closes when you click. But I didn't use
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord