Jay Long

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJay Long
ToMe
SubjectNested list collapsing script; How to Expand all Items
Date12 May 2006 17:32
Hi Tarquin,

First off, you're a wonderful asset to the developer community. Your
scripts are great and very appreciated - especially by those who aren't
as strong on the client-side (that would be me, btw) as they aspire to
be.

Anyway, this may be a bit of a silly question, but I am just wondering
if there is an easy method to expand/collapse all items w/I a nested
list. For example, something like: expandAll()/collapseAll() or a style
selector chg. Also, do you have a suggestion on what to include in a
"media=print" css, so that when printed, all items expand?

Thanks in advance and keep up the great work!

Regards,

Jay Long
FromMe
ToJay Long
SubjectRe: Nested list collapsing script; How to Expand all Items
Date14 May 2006 12:41
Jay,

> if there is an easy method to expand/collapse all items w/I a nested
> list.

Not built in, no (since in general, most of us provide this functionality,
but in fact, no-one actually uses it). But if you are sure you need it,
this should do it (basically, it looks through the list, and finds every
link with an onclick handler - if that seems to have a related child list,
it runs the onclick handler - a little messy, but it should work):

expanding:

function expandAll(oElID) {
 if(!document.getElementsByTagName||!document.childNodes) { return; }
 var oEl = document.getElementById(oElID);
 var oT = oEl.tagName;
 var oLinks = oEl.getElementsByTagName('a');
 for( var i = 0, oCUL; i < oLinks.length; i++ ) {
  if( oLinks[i].onclick ) {
   oCUL = oLinks[i].parentNode.getElementsByTagName( unescape(oT) )[0];
   if( oCUL && oCUL.style.display == 'none' ) {
    oLinks[i].onclick();
   }
  }
 }
}
...
expandAll('list id');

collapsing:

stateToFromStr('list id','rubbish');

Note that expandAll _will not work_ if you have set the list to
auto-collapse.

> do you have a suggestion on what to include in a
> "media=print" css, so that when printed, all items expand?

Since I set the display style manually, it will be applied to all media
types with highest cascading priority. I do not think you will be able to
override it.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.