Click to See Complete Forum and Search --> : How to expand/collapse all on javascript tree


cdonges
12-07-2003, 06:41 PM
I have a javascript tree made from this article:

http://www.devx.com/webdev/Article/9843/0

It works great but I can't work out how to have buttons to expand and collapse all.

Can somebody please help?


Chris

Nigel McFarlane
12-29-2003, 08:15 PM
The full DOM hierarchy of the tree can be navigated from JavaScript, even if only parts of the tree appear on the screen.

Look at the Node object in the DOM 1, 2 or 3 Core standard at w3.org. You can write a recursive function that starts at document and that uses childNodes() and nextSibling to walk down the whole tree. Set the display style on every node that your come across. When your script ends, the tree will be fully revealed or hidden.