Link to home
Start Free TrialLog in
Avatar of gpinzino
gpinzino

asked on

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.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

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
t127.html
Avatar of gpinzino
gpinzino

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial