I have a function that makes an accordion menu. It’s really handy because it saves a lot of real estate and provides a neat little piece of eye-candy for the end-user. Unfortunately, as it stands, it only accepts 1 ID for a single DIV of which to apply this menu to and I really need it to instead be applied to multiple DIVs within the DIV that makes the initial call of the function…
I’ll elaborate…
The calling function is this:
function runAccordion(index){
var nID = "comments";
if(openAccordion == nID)
nID = '';
setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
+ openAccordion + "','" + nID + "')", 33);
openAccordion = nID;
}
This function is called by an onclick method appended to an anchor / link. When the anchor / link is clicked on, this function makes the DIV that has the ID assigned within the variable nID “expand.” So in other words, if there’s a DIV with the ID of “comments” (like above), this calling function would make that DIV drop down to a designated height found in the external CSS file… Pretty straightforward.
What I would like to do is create a single function that initializes 1 array that contains the other DIV IDs that I would like to apply this menu system to. So for example, I would like to assign this aforementioned array the IDs of “updates”, “downloads”, etc. to provide the visitor with a collapsible menu system and by simply making 1 function that can accept the IDs seems like a good idea, right? Feedback on this is appreciated, too.
So anyway, how could I do this? I know it would have something to do with getElementById() and maybe 1 FOR loop, but the rest is a bit vague…
Any help on this would be appreciated.