Click to See Complete Forum and Search --> : getElementById


Dumbass
11-22-2003, 07:28 AM
getElementById.... Does this work in IE? If it does, I can't get it to work :/. If it doesn't, is there any kind of replacement for it?

gil davis
11-22-2003, 08:01 AM
Supported in version 5 and above.

Dumbass
11-22-2003, 08:26 AM
You're sure? I just whacked together a test page to test it, and got an error.

<html>
<head>
<script>
function testzuh()
{
var test1 = "div1";
getElementById(test1).style.width = 200;
}
</script>
</head>
<body onLoad="testzuh()">
<div id="div1" style="position:absolute; top:0px; left:0px; background-color: #000000; height:100px; width:100px">
&nbsp;
</div>
</body>
</html>

Unless there's something wrong with that page...

fredmv
11-22-2003, 08:37 AM
This will work:<script type="text/javascript">
onload = function()
{
document.getElementById("foo").style.backgroundColor = "#ff0000";
}
</script><div id="foo" style="height: 300px; width: 300px;"></div>

pyro
11-22-2003, 10:41 AM
You forgot the document before the getElementById, and you should specify the width like this:

document.getElementById(test1).style.width = "200px";

Dumbass
11-22-2003, 04:45 PM
Yeah, I realised that after having a close look at fredmv's code. Thanks :)