Does anyone know how I could go about randomising an unordered list each time the page is refreshed?

A jQuery solution would be perfect as I'm already using it for other effects.

Any advice appreciated!

1 answer

o.k.w 2355
This was chosen as the best answer

There you go:

Javascript using jQuery:

$(document).ready(function() {
 var arrLi = []; // an array to store the list items
 var parent = $('ul'); // get the parent UL
    //move the items into the array
 var rnd = 0; // declare random variable
    //generate random number between 0 and array length
    rnd = Math.floor(Math.random()*arrLi.length);
    //move random item into parent UL
    parent.append($('<li>' + arrLi.splice(rnd, 1) + '</li>'));


Answered about 8 years ago by o.k.w
  • brilliant! many thanks! Warren about 8 years ago
  • @Warren, not the perfect implementation but glad it works for you :) o.k.w about 8 years ago