Thursday, November 8, 2007

Great DIV hide JavaScript code

 My thanks to Lobo235 for his code that helped me with the collapsible fieldset:

<fieldset>
<legend onclick="toggleLayer( 'divComponentInfo', 'expandImg' )" onmouseover="this.style.cursor='hand'">
<img alt="expand" id="expandImg" src="images/expand_plus.gif" style="vertical-align:middle;padding-right:5px;" />Component information</legend>
<div id="divComponentInfo" style="display:none">

function toggleLayer( whichLayer )
{
var elem, vis;
if( document.getElementById ) // this is the way the standards work
elem = document.getElementById( whichLayer );
else if( document.all ) // this is the way old msie versions work
elem = document.all[whichLayer];
else if( document.layers ) // this is the way nn4 works
elem = document.layers[whichLayer];
vis = elem.style;
// if the style.display value is blank we try to figure it out here
if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

No comments: