Expanding nested lists with JavaScript

I am working on a web page where is need to hide and reveal text in stages. Conceptually, the page would look something like this.

MainTopic 1
Subtopic 1.1
Subtopic 1.2
Subtopic 1.3
Subtopic 1.4

Full Description 1.4
MainTopic 2
MainTopic 3
MainTopic 4

Initially, all the user would see is the list of 4 main topics. Click on a main topic and a list of subtopics appears directly beneath the main topic. Click on any subtopic and a full description, usually 5 to 10 lines of text, appears beneath the subtopic.

Using innerHTML in Javascript, I have no problem creating the first level of expansion – getting to the subtopics. The problems start with trying to get the full descriptions to pop up. It appears to require nested functions, and I cannot get them to work together.

Is there a solution to this issue? A little code example would be a great help.
Who is Participating?
Julian HansenCommented:
A few small changes
Julian HansenCommented:
This is an example of what you might be looking for. Might need tweaking depnding on whether you want only one panel to show at a time - i.e. if open panels must close when new panel / subitem selected
gpinzinoAuthor Commented:
Thanks for the quick response. This certainly looks good. Yes, I would need it to open only one panel at a time. How would I modify the code to do that?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.