On 6 sep, 09:02, GianCarlo Mingati <[EMAIL PROTECTED]>
wrote:
> ok, it is better to have the images in an array, and then construct
> the list.
> But is there a way with jquery of changing the order of a list?
> GC

Here is a idea. That's a function based on the fisher-yates shuffle
(thanks to perldoc perlfaq4).

Pass it a jquery object that contains your li. (or you could extend
jquery with it)

--<snip>--

function scramble(a) {
    var i = a.size();
    if (!i) return false;
    while (--i) {
        var j = Math.floor(Math.random() * (i+1));
        var tmp = a.slice(i, i+1);
        a.slice(j, j+1).after(tmp).insertAfter(tmp);

    }
}

$(document).ready(function() { scramble($('ul#foo li')); });

--</snip>--

Regards,
Renaud Drousies

Reply via email to