I am having trouble with a piece of javascript code that expands blocks of text. For example, when you click the title, the text under it will expand. I am fairly new to javascript but it looks like the code bassically re-writes the link in the html so that when you press the title again, it will collapse the text.
Here is the javascript code...
function expand(ID,name)
{
document.getElementById('item'+ID).style.display = 'block';
document.getElementById('expander'+ID).innerHTML =
'<a href="javascript:collapse('+ID+',\''+name+'\')" title="Collapse"><img alt="less" src="images/arrow_back.gif" width="20" height="10" class="no_border" /> <span id="expander1" class="style_heading3">'+name+'</span><br /></a>';
}
function collapse(ID,name)
{
document.getElementById('item'+ID).style.display = 'none';
document.getElementById('expander'+ID).innerHTML =
'<a href="javascript:expand('+ID+',\''+name+'\')" title="Expand"><img alt="more" src="images/arrow.gif" width="20" height="10" class="no_border" /> <span id="expander1" class="style_heading3">'+name+'</span><br /></a>';
}
Here is the HTML code...
<div id="expander1" class="expander" style="display: inline">
<a href="javascript:expand(1, 'TITLE')" title="Expand">
<img alt="more" src="images/arrow.gif" width="20" height="10" class="no_border" />
<span class="style_heading3">TITLE</span><br />
</a>
</div>
<div id="item1" style="display: none">
Expanded text goes here
</div>
The problem that I am having is that when you open the page in Mozilla Firefox or Safari, the boxes do not expand and collapse properly after you have expanded and collapsed it once. The code works perfectly fine in IE7. I am really stuck and cannot figure out why the java code would work fine in IE and not Firefox/Safari.
If anyone has any advice on how to accomplish this or how to tweak my current code to work on other browsers it would be very appreciated.