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
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.
MainTopic 1
Subtopic 1.1
Subtopic 1.2
Subtopic 1.3
Subtopic 1.4
Full Description 1.4
MainTopic 2Subtopic 1.2
Subtopic 1.3
Subtopic 1.4
Full Description 1.4
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
t127.html