[thelist] javascript for expand/collapse list (aka tree view)

Peter-Paul Koch gassinaumasis at hotmail.com
Tue Aug 12 17:14:01 CDT 2003

> > I am looking for some JavaScript for an expandable/collapsible "tree 
> > list (i.e. an unordered list in HTML). It only needs to work in Internet
> > Explorer 6 and Netscape 6+/Mozilla, as it is for a limited number of
> > who all have similar computers. I have a general idea of how this would 
> > done with JavaScript using the onclick of each <li> and using childNodes
> > and parentNodes to do the hiding/showing of the list; I just don't want 
> > spend a whole lot of time trying to "re-invent the wheel". Basically, I
> > just want to make my client happy by adding this functionality to their
> > site, so I'm looking for a quick and dirty solution - but with nice 
> > code :) So if anyone knows of an existing script which does something 
> > this, could you please point me to it?
>i found this one recently, couldn't be much simpler to implement (you just
>have to apply a class to the outermost <ul> tag)
>the downside is clicking the img doesn't open the tree like in others.

And that it doesn't work in IE Mac because of the unnecesarily complicated 
event handler registration. If you change the addEvent function to the code 
below it should work everywhere.

function addEvent(obj, evType, fn){
  obj['on'+evType] = fn;

ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
New: Browser Wars II: The Saga Continues

The new MSN 8: advanced junk mail protection and 2 months FREE* 

More information about the thelist mailing list