Forum Moderators: open

Message Too Old, No Replies

Moving a div Netscape

Code for moving a div using Netscape browser

         

Adam5000

8:52 am on Feb 25, 2006 (gmt 0)

10+ Year Member



Thanks to everyone who has helped. You're doing a great job and you're all fabulous.

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>

Bernard Marx

1:25 pm on Feb 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Adam500,

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>