Skip to content
  • Learning paths
  • Challenges
  • Solutions
  • Articles
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 1 year ago

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

web-components
Oscar Torres•150
@ozkrTr
A solution to the FAQ accordion challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I hope you like this solution, and I would appreciate your comments with observations and constructive criticism to continue improving my code.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Daniel 🛸•44,740
    @danielmrz-dev
    Posted over 1 year ago

    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 and display: block. I used height: 0 and height: 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

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub