We help IT Professionals succeed at work.

Javascript not working in IE but works in Firefox, Chrome etc.

Last Modified: 2013-12-08
Hi Experts,

Im currently developing a music site with some javascript in the navigation. When you click on Say News, Band, Tour etc the sub links appear below.... Then if you clicked on the next one the previous one closes... its basically a Javascript Show/Hide script.

It works on Chrome & Firefox but not on IE.... obviously its important that it works on i.e. as the site is for one of the worlds largest bands soo its pretty important that i resolve this quickly.

<script language="JavaScript">
//here you place the ids of every element you want.
var ids=new Array('news','band','tour','music','media');
function switchid(id){	
function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		else { // IE 4
			document.all.id.style.display = 'none';
function showdiv(id) {
	//safe function to show an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		else { // IE 4
			document.all.id.style.display = 'block';
HTML Code:
<td height="27"><a href="javascript:switchid('news');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('News','','images/images/leftnav_ov__02.png',1)"><img src="images/images/leftnav_02.png" alt="News" name="News" width="171" height="27" border="0" id="News" /></a><div id='news' style="display:none;" class="content2" align="right"><a href="news.php">News</a><img src="images/spacer.gif" width="5" height="1"><br><a href="archive.php">Archived</a><img src="images/spacer.gif" width="5" height="1"></div></td>

Open in new window

Watch Question

Top Expert 2007
This one is on us!
(Get your first solution completely free - no credit card required)
Top Expert 2007

I tested this in IE 8 and Firefox 3.0.8 - both seemed to work.

Not knowing what the two "MM" function looked like, I made some assumptions for expediency.


will give it a go later and let you know :o) cheers for getting back to me!
Top Expert 2007

Hey, its part of the plan!
Top Expert 2007


I noticed that there is an <img> tag with the [id] of "News" and a <div> tag with an [id] of "news". I would consider these to be unique (but fraught with peril) but IE does not - so I changed the <img> tag [id] to "img_news". That made a BIG difference.

Sorry I didn't see that earlier...
Top Expert 2007

Is this still an issue?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.