C
cjl
Hey all:
I'm stuck. I'm using the code from www.quirksmode.org for cross
browser access to HTML elements, but I'm getting a javascript error.
The relevant code:
function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
this.obj = document.layers[name];
this.style = document.layers[name];
}
}
OK -- this is straight from quirksmode, and I have seen the same or
similar code in just about every javascript library. I have the
following HTML:
<img id="right_image" src="data/1.gif" alt="right image" />
And the following css:
#right_image
{
position: absolute;
}
So, when I call:
var rightImage = new getObj('right_image');
I get an error:
"Error: document.getElementById(name) has no properties"
However, if I comment out "this.style =
document.getElementById(name).style;" from the getObj function, the
error goes away.
So, what am I doing wrong?
-CJL
I'm stuck. I'm using the code from www.quirksmode.org for cross
browser access to HTML elements, but I'm getting a javascript error.
The relevant code:
function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
this.obj = document.layers[name];
this.style = document.layers[name];
}
}
OK -- this is straight from quirksmode, and I have seen the same or
similar code in just about every javascript library. I have the
following HTML:
<img id="right_image" src="data/1.gif" alt="right image" />
And the following css:
#right_image
{
position: absolute;
}
So, when I call:
var rightImage = new getObj('right_image');
I get an error:
"Error: document.getElementById(name) has no properties"
However, if I comment out "this.style =
document.getElementById(name).style;" from the getObj function, the
error goes away.
So, what am I doing wrong?
-CJL