I'm trying to change the class of a div using the onclick notifier of an object. The code looks like it should work, but when I'm troubleshooting with Firebug, it appears that my for loop (that even Firebug shows having only 1 element in it) executes more than once and throws an error the second time around. Here's the Javascript:
function handleElements(elementid,containerid) {
// Get array of all 'visible' elements in the container
var elements = document.getElementById(containerid).getElementsByClassName('visible');
// Iterate over that array and make them all 'hidden'
for (var i in elements) {
var object = elements[i].id;
document.getElementById(object).className='hidden';
}
// Get the 'clicked' tab and set it to 'visible'
var clicked = document.getElementById(elementid);
clicked.className='visible';
}
And here is the HTML:
<div id="wrapper">
<div id="leftpanel">
<div id="navcontainer">
<ul id="navlist">
<li><a href="javascript:;" onClick="handleElements('Modules','rightpanel')">Modules</a></li>
<li><a href="javascript:;" onClick="handleElements('DataViewer','rightpanel')">Data Viewer</a><li>
<li><a href="javascript:;" onClick="handleElements('Alarms','rightpanel')">Alarms</a><li>
<li><a href="javascript:;" onClick="handleElements('Logging','rightpanel')">Logging</a><li>
<li><a href="javascript:;" onClick="handleElements('Outputs','rightpanel')">Output Control</a><li>
</ul>
</div>
</div>
<div id="rightpanel">
<div id="Modules" class="visible">
<h2>Module Information Here</h2>
</div>
<div id="DataViewer" class="hidden">
<h2>Data Viewer Here</h2>
</div>
<div id="Alarms" class="hidden">
<h2>Alarm Page Here</h2>
</div>
<div id="Logging" class="hidden">
<h2>Logging Setup Here</h2>
</div>
<div id="Outputs" class="hidden">
<h2>Output Control Here</h2>
</div>
</div>