jquery move elements into a random order
After much exploration, I decided to take the fisher-yates algorithm and apply it with jquery without requiring cloning, etc.
$('#tout4 img.img_lg').shuffle();
/*
* Shuffle jQuery array of elements - see Fisher-Yates algorithm
*/
jQuery.fn.shuffle = function () {
var j;
for (var i = 0; i < this.length; i++) {
j = Math.floor(Math.random() * this.length);
$(this[i]).before($(this[j]));
}
return this;
};
You can also use the common JavaScript Array randomize sorter, also commented here and here:
$('<my selector>').sort( function(){ return ( Math.round( Math.random() ) - 0.5 ) } );