473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

IE getElementById problem ? getElementsByTagName problem ?

I have made up a code allowing users to click on a tab and show content in a neat white box, similar to what yahoo have on their homepage.
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
  1. function showdiv(div, link) {
  2. divs = document.getElementById('features').getElementsByTagName('div');
  3. links = document.getElementById('links').getElementsByTagName('a');
  4.     for (i = 0; i < divs.length; i++) {
  5.         divs[i].style.display = "none";
  6.         links[i].style.background = "#FFFFFF";
  7.     }
  8.     document.getElementById(div).style.display = "block";
  9.     link.style.background = "#99FFCC";
  10. }
  11.  
and here is the HTML (simplified to make it more readable):

[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="&copy; 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 &quot;other&quot; 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
Feb 24 '08 #1
3 3575
acoder
16,027 Expert Mod 8TB
Seems to work on IE7 unless I've missed something.
Feb 25 '08 #2
It shouldn't do... strange, maybe IE doesn't like variable names to be the same as the id names of tags
Feb 26 '08 #3
acoder
16,027 Expert Mod 8TB
When you say it doesn't work, what happens? Is there an error message?
Feb 26 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
6
by: MNF | last post by:
Hi everyone, I am using document.getElementById function in JavaScript to find a control within an html body, but instead I get back META item, because incidently the name of one meta tags is the...
3
by: InvisibleMan | last post by:
Thanks in Advance for any help on this - its truely sending my head in loops... so I appreciate your efforts! okay, I have a javascript listed below that drops down submenus contained within:...
24
by: Robi | last post by:
I have the following problem: I populate a page with a specific amount of <div id="MyTest"> containers inside another <div> container. for (i=0; i < MyString.length; i++) document.write('<div...
4
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6...
10
by: Nik | last post by:
Hello! Thanks for reading my question first! I have many divs with an numeral id ,for example <div id="999">...</div>, <div id="1000">...</div> and I wish to do something like this, for(...
3
by: edai | last post by:
I am working on a code where I am loading XML data from a file on the server using ....... if (xmlhttp.readyState==4) { value=xmlhttp.responseText; var parser=new DOMParser();...
45
by: phub11 | last post by:
Hi, I have a JS function which includes the following lines: var table = document.getElementById("table1"); var cells = table.getElementsByTagName("div"); for (i = 0; i < cells.length; i++)...
7
by: SM | last post by:
Hello, i need to add a classname to an element <ausing JavaScript. I've tried a couple of thing with no success. This is an small piece of my code: .... <li><a href="<?php echo $cd_img; ?>"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.