Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

javascript problem with getElementById in Explorer

This is a discussion on javascript problem with getElementById in Explorer within the JavaScript forums, part of the Web Development category; Hello, The html code (with javascript) shown below works in all browsers except IE. I recently learned that IE don't want to handle the getElementById and id codes. Is somebody ...

Go Back   Geeks Talk > Web Development > JavaScript
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 08-24-2009
Junior Member
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
erikgi is on a distinguished road
javascript problem with getElementById in Explorer

Hello,

The html code (with javascript) shown below works in all browsers except IE.

I recently learned that IE don't want to handle the getElementById and id codes.

Is somebody so kind to advise me, is there another way to get it work or is there a workaround code?

Thanks in advance, Erik

In order to read the html code I changed < and > in [ and ].

HTML Code:
[head]
[meta http-equiv="content-type" content="text/html; charset=utf-8" /]
[meta http-equiv="X-UA-Compatible" content="IE=8" /]
[title]test[/title]
[script type="text/javascript"]
[!--
var color = new Object();

color["100"] = new Array("300", "400");

color["200"] = new Array("100", "300", "400");

color["300"] = new Array("100", "200");

color["400"] = new Array("200");

var colors = new Array("related");

function on(id)
{
for (var i=0; i[color[id].length; i++)
{
var el = document.getElementById("index_"+color[id][i]);
if (el)
{
el.setAttribute("class", colors[i%1]);
}
}
}

function off(id)
{
for (var i=0; i[color[id].length; i++)
{
var el = document.getElementById("index_"+color[id][i]);
if (el)
{
el.removeAttribute("class");
}
}
}
//--]
[/script]

[style type="text/css"]
[!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
line-height: 18px;
color: #000000;
text-decoration: none;
}
a:link,
a:visited {
color: #000000;
text-decoration: none;
}
a:hover,
a:active {
color: #FF0000;
text-decoration: underline;
}
a.related {
color: #FF0000;
text-decoration: none;
}
--]
[/style]
[/head]

[body]

[a href="#" id="index_100" name="index_100" onMouseOver="on(100)" onMouseOut="off(100)"]aaa[/a][br /]
[br /]
[a href="#" id="index_200" name="index_200" onMouseOver="on(200)" onMouseOut="off(200)"]bbb[/a][br /]
[br /]
[a href="#" id="index_300" name="index_300" onMouseOver="on(300)" onMouseOut="off(300)"]ccc[/a][br /]
[br /]
[a href="#" id="index_400" name="index_400" onMouseOver="on(400)" onMouseOut="off(400)"]ddd[/a]

[/body]

Last edited by erikgi; 08-24-2009 at 11:07 AM. Reason: mistakes
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-25-2009
Junior Member
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
erikgi is on a distinguished road
Re: javascript problem with getElementById in Explorer

Problem solved.

el.setAttribute("class", colors[i%1]);
and
el.removeAttribute("class");

are replaced with

el.className = colors[i%1];
and
el.className = "";

This works splendid in IE (and all the other browsers).
Reply With Quote
Reply

  Geeks Talk > Web Development > JavaScript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Window explorer virus shivindkaur Windows 2 07-14-2009 02:34 PM
Problem with explorer gReaen Windows 0 01-31-2008 07:28 AM
What is the difference between Internet Explorer and Mozilla Firefox pushpalatha.a Testing Issues 5 12-06-2007 08:59 AM
10-Strike Network Inventory Explorer is a program for compiling the hardware and soft JobHelper Geeks Lounge 0 07-04-2007 02:32 PM
AccelMan File manager: award-winning explorer replacement. JobHelper Geeks Lounge 0 04-23-2007 08:00 AM


All times are GMT -4. The time now is 01:31 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved