Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

youlichika

macrumors member
Original poster
Aug 27, 2010
35
0
I have 3 divs. I want distribution them random (when refresh the windows, three divs' position will be changed)
I think Math random() can solve this problem, but how to do that? Thanks.

Code:
<div id="div1">...</div>
<div id="div2">...</div>
<div id="div3">...</div>
<script>
Math.floor(Math.random()*3)+1;
...
</script>
 
PHP:
var divID = 'div' + Math.floor(Math.random()*3)+1;
var theDiv = document.getElementByID(divID);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.