Skip to content
Advertisement

How to collapse/expand accordion in a Q&A form after input selection

Not sure if that’s the correct vocabulary, but here’s what I’m trying accomplish. I’m working with a team on this big multi-page Q&A application, my task is make one particular page use the least amount of screen real estate as possible.

I’m using an accordion, each one has a question inside, and next to each question is a question mark which changes to check mark after the question is answered.

I have all that already completed which you can see here:

JavaScript
JavaScript
JavaScript

Here’s where I’m stuck.

Once I select an answer for a question, I want the accordion to collapse to the next question, of course, it will only apply to single answer fields.

  1. How do I expand the next question after I select an answer for the previous question?
  2. How do I change the question mark to a check mark after I select an answer?

Advertisement

Answer

You can surround each “accordion” with a div (i gave it a class accordion_main)

add the check mark classes and remove the question class.

The html will look like this:

JavaScript

and js:

JavaScript

working fiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement