Forum Moderators: open
What I'm trying to do now, is move a div left and right, up and down, when the page is viewed with the Netscape browser. I think the way to do this differs a little between MSIE and Netscape, but I'm not sure. And I think the code below is close. Help!
<html>
<head>
<title>Move div Netscape</title>
</head>
<body>
<div id="netscape1" style="position:absolute; top:100; left:100;">
<img src="picture 3.jpg">
</div>
<script language="javascript">
window.document.netscape1.left = window.document.netscape1.left +300;
</script>
</body>
</html>
I mean no rudeness, but for emphasis I should say that whatever documentation ¦ tutorial you are following is hopelessly out of date, and probably proprietary to a particular browser. Use W3C DOM methods.
1) Reference the id'd element using document.getElementById
2) Always specify units in CSS pos/dim values. Many browsers will no longer assume "px"
3) Get position values via the element's style object.
4) The value returned is a string that includes the units, which must be parsed out.
<script language="javascript">
var elmStyle = document.getElementById("netscape1").style;
elmStyle.left = (parseInt(elmStyle.left)+300)+"px";
</script>