Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

FAQ Accordion Card

Jordan J 90

@jordanr2m

Desktop design screenshot for the FAQ accordion card coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


I was struggling with this one. Any advice is greatly appreciated!

Community feedback

Carl 815

@CarlHumm

Posted

Hi there, nice try

Your JS doesn't work as accordionContent is a nodelist, not an element

You are attempting to toggle a class on accordionContent which, like accordionHeadings, is a nodeList and not an element. For each click, we instead want to reference the accordion-content relative to the clicked element. How do we do that?

Here are just two common options.

  1. i.nextElementSibling.classList.toggle('hidden')
  2. i.parentElement.querySelector('.accordian-content').classList.toggle('hidden')
accordianHeadings.forEach(function (i) {
    i.addEventListener("click", function () {
        // Replace me 
    })
})

So i references the clicked element (the heading). Working from the heading we can either go up one to the parent and search for accordion-content, or use the nextElementSibling property. Since our accordion is composed of headings and content, the nextElementSibling will always be the accordion-content which works well for us.

Alternatively you could use the HTML Details & Summary Elements

<details>
  <summary>Accordion Heading</summary>
  Something small enough to escape casual notice.
</details>

Unfortunately I only had time to write a solution for the JS. Perhaps someone else can help with the layout and images.

Good luck on your future projects

Marked as helpful

1

@HamzehDehnavi

Posted

Best my friend

0

Please log in to post a comment

Log in with GitHub
Discord logo

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