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. |
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 ...
|
|||||||
|
|||
|
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 |
| Sponsored Links |
|
|||
|
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). |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
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 |