PDA

View Full Version : Could javascript, or SOMETHING edit <div> tag attributes?


HELLSS
11-05-2002, 11:50 AM
<div style="position:absolute; top:300; left:540; ">stuff</div>

What I am looking for is a way to randomize the top and left numbers within a 100+ or - area. So when a page is refreshed, everything within the div tag is moved to the new coordinates. I might use this on pages with more than one of the above div tags so it would need to be able to be associated with only certain div tags.

I have no clue how to go about figuring this out and havent found anything which would do the job. Any help would be greatly appreciated, even if the help is saying that no it can't be done :)

Mr J
11-05-2002, 12:08 PM
Have a play with this:

add onload="move()" to the opening body tag



<script lanfuage="Javascript">
<!--
function move(){
x=Math.floor(Math.random()*500)
y=Math.floor(Math.random()*300)
document.getElementById('oDIV').style.pixelLeft=x
document.getElementById('oDIV').style.pixelTop=y
}

// -->
</script>

<div id="oDIV" style="position:absolute;left:100;top:100">Hello World</div>

HELLSS
11-05-2002, 01:12 PM
*bows repeatedly to the might of Mr J*

You'r powers at helping others almost match that of Mr T :D

Thank you thank you very very much.