PDA

View Full Version : Switch Content Script - Multiple DIVs Open By Default



bdkyle
06-29-2006, 06:02 AM
Script: Switch Content Script
http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm

First, let me thank the authors of the site for a collection of great scripts. I particularly like this one for its fantastic backwards compatibility.

I would like to setup the script to automatically have several divs open by default. For example, on a page with twelve div "sections" I would like to have sections one, three, eight, and nine "open" by default with the others "closed" but set to open upon click. It's fine to either specify these within the div or within the javascript, as I want it displayed the same way on each page.

I've dug through the forums and found a variety of relevant postings. Unless I've overlooked something, this (http://www.dynamicdrive.com/forums/showthread.php?t=10414&highlight=switch+content+open) doesn't seem to work with the current "Switch Content Script" from the URL at the top.

Those instructions do work using the script in the third message in this post (http://www.dynamicdrive.com/forums/showthread.php?t=7823&highlight=switch+content+open), but it isn't quite as advanced as the "Switch Content Script", so I'd rather use it if at all possible.

Following the instructions in this post (http://www.dynamicdrive.com/forums/showthread.php?t=3949&highlight=switch+content), I had no problem modifying the stock Switch Content Script to have one DIV open by default by finding "revivestatus()" at the end of the "function do_onload(){" and changing it to this:


revivestatus()
sweeptoggle('contract')
expandcontent(statecollect[0].parentNode, 'sc1');

That will make the first section open by default, but I'm not sure how to change it to make other sections open as well. What am I overlooking?

Thank you very much for your help.

jscheuer1
06-29-2006, 06:48 AM
You can add as many of those type statements as you need, for example, to have the first two open use:


revivestatus()
sweeptoggle('contract')
expandcontent(statecollect[0].parentNode, 'sc1');
expandcontent(statecollect[1].parentNode, 'sc2');

Notice the format, statecollect[#] is one less that sc#.

bdkyle
06-29-2006, 03:26 PM
D'oh! I swear I already tried that, as it was the intuitive thing to do, but I must have forgotten to change statecollect. That works perfectly. Thank you.