[thelist] collapsible elements without using IDs

Matt Warden mwarden at gmail.com
Mon Dec 6 17:45:41 CST 2004


List,

I have been working on methods of collapsing elements (for good
reason, I swear). I have it working using ID attributes. You can see
that here:

http://mwarden.f2o.org/sandbox/collapsible_elements.htm

However, the site on which this will be used is highly dynamic, and it
would be so very useful to not have to identify page elements by a
unique ID. I played with passing "this" rather than using
getElementById() and then playing around with traversing the DOM tree,
but as it turned out the object referenced by "this" didn't seem to be
the current element in the DOM tree.

Further, examples i googled up did not do what I was looking to do
(however, I found something close in this list's archives, but again I
couldn't use it because 'this' didn't seem to be the object I could
use nextSibling, etc. on)

The function of interest is below:

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.


-- 
Matt Warden
Miami University
Oxford, OH
http://mattwarden.com


This email proudly and graciously contributes to entropy.


More information about the thelist mailing list