I have used 5 divs, all but one set to display:none and the other (the one seen at the start is set to display:block and the script makes the desired div become display:block and makes the div previously display:block to be display:none here is my js code:
Expand|Select|Wrap|Line Numbers
- function showdiv(div, link) {
- divs = document.getElementById('features').getElementsByTagName('div');
- links = document.getElementById('links').getElementsByTagName('a');
- for (i = 0; i < divs.length; i++) {
- divs[i].style.display = "none";
- links[i].style.background = "#FFFFFF";
- }
- document.getElementById(div).style.display = "block";
- link.style.background = "#99FFCC";
- }
[HTML]<div id="blockoffeatures">
<p id="links">
<a href="javascript:void(0)" onclick="showdiv('LatestPhoto', this)" style="background:#99FFCC">Latest Photo</a>
<a href="javascript:void(0)" onclick="showdiv('LatestObs', this)" style="background:#FFFFFF">Latest Obs.</a>
<a href="javascript:void(0)" onclick="showdiv('LatestUpdates', this)" style="background:#FFFFFF">Latest Updates</a>
</p>
<div id="features">
<div id="LatestPhoto" style="display:block;">
<h4>Latest Photo</h4>
<img src="Resources-folder/snakes/IMG_8615.jpg" alt="© djp1988" width="400" height="240" border="1" />
</div>
<div id="LatestObs" style="display:none;">
<h4>Latest Observations</h4>
<p>22nd Feb. : Malpolon monspessulanus, Psammodromus algirus, Pelophylax perezi</p>
</div>
<div id="LatestUpdates" style="display:none;">
<h4>Latest Web Site Updates</h4>
<p >23rd Feb. : New homepage design, I have put the search bar in the menu for handy access, I have put the Sources, Site Info., Books and Links into a drop down menu over the "other" link and grouped all the usually features in this wonderful JavaScript powered area.
</div>
</div>
[/HTML]
It works in FF, Safari (mac), Opera (mac) but not on IE any version. I think there is a problem IE have with the getElementById, but how to fix it and is there also a problem with the getElementsByTagName in IE ?
The finished product (with a hack i am testing - but i can't test because i am on a mac and have no IE) is found here: www.herpfrance.com