[thelist] collapsible elements without using IDs

Christian Heilmann lists at onlinetools.org
Mon Dec 6 18:52:57 CST 2004


>function toggleExpanded(oelement)
>{
>	if (oelement && oelement != null)
>	{
>		// toggle expanded/collapsed
>		if (oelement.className && oelement.className != null)
>			oelement.className =
>(oelement.className.toLowerCase()=='collapsed'?'expanded':'collapsed');
>		else
>			oelement.className = 'collapsed';
>		// end if
>	} // end if
>}
>
>(also, is the if I'm using to check for a valid object redundant? I'm
>not sure if the first condtion could ever return true yet the object
>is still null)
>
>Any help would be greatly appreciated.
>
>
>  
>
Yes, it is redundant, especially when you call this function from the 
element.

What you can do is to add this function onclick to each A element inside 
one with an ID by looping through its document.getElementByTagName('a') 
array then your function should apply the above functionality to the 
next sibling. An example would be the demo page of the cssjs function:

http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html

HTH

Chris

P.S: Never, under _any_ circumstances use javascript: as a link 
protocol. It is a bad habit that MUST die.






More information about the thelist mailing list