Click to See Complete Forum and Search --> : moving a div with javascript


beki
09-09-2003, 06:42 AM
How can I move a div element with javascript?

I can do this:
document.all["tussen"].style.top= 200

so it moves to 200, but what I want is to move it 200 pxs down. I want to do something like this:
document.all["tussen"].style.top+= 200
or
document.all["tussen"].style.top= document.all["tussen"].style.top + 200
or
var temp = document.all["tussen"].style.top
document.all["tussen"].style.top = (temp+200)

but these things dont work..

any id's?

Khalid Ali
09-09-2003, 06:48 AM
try the link below,its actually allot better solution since it will work with most browsers that has JS enabled.

http://www.webapplikations.com/pages/html_js/document/SimpleVerticalDivScroll.html

Fang
09-09-2003, 07:01 AM
top returns a string - it doesn't recognise if it's px or %
X-browser:
var t=parseInt(document.getElementById('tussen').style.top);
document.getElementById('tussen').style.top=t+200+"px";