Randomised division selection

Bit of an odd one.... How can I get a website to *random*ly select a division to show each time the page is loaded? I have absolutely no idea where to start.

<body>
     <div id="option1">Dog</div>
     <div id="option2">Cat</div>
     <div id="option3">Rabbit</div>
</body>

Thanks!!

Answers


I would recommend doing something in Javascript.

When the body load you should tell Javascript either to remove the once you dont want or to create the one you want.


Update:

This will delete all divs but the one selected randomly.

Html

<head>
    <script type="text/javascript" src="script.js"></script>
</head>

<body onload="load()">
    <div id="1">
    </div>
    <div id="2">
    </div>
    <div id="3">
    </div>
</body>

Javascript

function load() {   
    var amount_of_divs = 3;
    var random = Math.floor((Math.random()*amount_of_divs) + 1);

    for (var i = 1; i < amount_of_divs + 1; i++) {
       if(i == random)
           continue;
       var div = document.getElementById(i);
       div.parentNode.removeChild(div);
    }
}

Need Your Help

NSImage color shift on Snow Leopard

macos cocoa quartz-graphics

My app creates NSImages by compositing various other NSImages together. The original images are loaded from files using [NSBitmapImageRep imageRepWithContentsOfFile:]. The final image is then displ...