How to use Math random() distribution three div?

Discussion in 'Web Design and Development' started by youlichika, Nov 12, 2010.

  1. youlichika macrumors member

    Joined:
    Aug 27, 2010
    #1
    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>
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    PHP:
    var divID 'div' Math.floor(Math.random()*3)+1;
    var 
    theDiv document.getElementByID(divID);
     

Share This Page