javascript in IE6 v NN7.1 & Firefox

S

Stephen T. Fox

I have a test sample that I have been experimenting with for no particular
purpose other than learning something. I have published a sample here
http://www.stephenfox.us/test101104js.html to illustrate the problem.

<head><style type="text/css">
#houdini {position: absolute;
top: 0;
left: 0; }
</style>
</head>
<body>
<div id="houdini"><img src="images/houdini4_small.jpg" width="37"
height="37" alt="Houdini" />
<script type="text/javascript">
houdini.style.top = "250px"
houdini.style.left = "270px"
</script>
</div>
</body>

This works OK in IE, moving the image to the new coordinates, but in both
other browsers, the image is at top:0; left:0; . The error message reads
"houdini not defined" . I have been going through several tutorials, etc to
find out how houdini should be 'defined' and have come up blank.
I'm sure the solution is something very simple and I'd appreciate any help
you can offer.

Thanks.
 
D

DU

Stephen said:
I have a test sample that I have been experimenting with for no particular
purpose other than learning something. I have published a sample here
http://www.stephenfox.us/test101104js.html to illustrate the problem.

<head><style type="text/css">
#houdini {position: absolute;
top: 0;
left: 0; }
</style>
</head>
<body>
<div id="houdini"><img src="images/houdini4_small.jpg" width="37"
height="37" alt="Houdini" />
<script type="text/javascript">
houdini.style.top = "250px"
houdini.style.left = "270px"
</script>
</div>
</body>

This works OK in IE, moving the image to the new coordinates, but in both
other browsers, the image is at top:0; left:0; .

That's because you're using an MSIE-only way to reference an element.
Best is to use a W3C web standards way to reference an element because
most browsers currently in use support these.
document.getElementById("houdini")
is supported by MSIE 5.x, MSIE 6, MSIE 5.x for Mac, Opera 6, Opera 7,
Netscape 6.x, Netscape 7.x, Mozilla 0.9.x, Mozilla 1.x, Safari 1.x,
Konqueror 3.x, etc. and
document.getElementById(idNodeValue)
is forward-compatible, future proof.

The error message reads
"houdini not defined" . I have been going through several tutorials

Really?

, etc to
find out how houdini should be 'defined' and have come up blank.
I'm sure the solution is something very simple and I'd appreciate any help
you can offer.

Thanks.

http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-getElBId

DU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top