Moving DIV element

  • Thread starter Thomas Scheiderich
  • Start date
T

Thomas Scheiderich

I am trying to get this section to move and I can't seem to get it to move.

When I click the words or image - it should move, but it isn't.

What am I missing?

*************************************************************
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title></title>
</head>
<body>

<script language="javascript">
function moveObject()
{
alert("this is a test");
var object=document.getElementById('object1');
object.style.top=60 + 'px';
object.style.left=120 + 'px';
alert("this is a test2");

}
</script>

<div id="object1" onclick="moveObject()" >
This is a test<br><img src="msft_118x35.gif">
</div>
</body>
</html>
*********************************************************

Thanks,

Tom
 
J

Jan Clemens Faerber

Thomas said:
What am I missing?

alert("this is a test");
var object=document.getElementById('object1');
object.style.position='absolute';

object.style.top=60 + 'px';
object.style.left=120 + 'px';


coming from: div { position:absolute; top:60; left:120; }

Jan
 
J

Jan Clemens Faerber

Thomas said:
That was it.

Why does it need to be absolute?

haha - I am happy I found it. (-:
No, it is not necessary to be absolute I think - it´s just one
possiblity. But obviously 'position' has to be declared somehow.
Because else 'top' and 'left' feel 'alone'.

Actually I found that when studing this script - because of the css
definition class="countdown" - so I thought your <div> definition was
not complete:


<style type="text/css">
<!--
.countdown {}
-->
</style>
<script language="JavaScript1.2" type="text/javascript">
<!--
var countdown;
function showCountdown(){
sec = countdown/1000;
document.countdown.timer.value = sec + ' seconds';
countdown-=1000;
}
function autologout(timer){
logout = window.setTimeout("logoutUser()",timer);
countdown = timer;
cInterval = window.setInterval("showCountdown()",1000);
}
//-->
</script></head>
<body onload="self.focus();autologout(60000);">
<form name="countdown">
<input type="text" name="timer" size="14" maxlength="14" class="countdown">
</form>

Jan

j.f Vienna
 
T

Thomas Scheiderich

Toby Inkster said:
Don't use @xmlns unless you're using XML.

I only used it as I was trying to find out why my div code wasn't working
and that was in some of the other files I was looking at.

Thanks,

Tom.
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top