/***
Adrien Clerbois
Correction for stackoverflow post (http://stackoverflow.com/questions/16529263/adding-an-input-match-randomizer-with-js-jquery)
*/
$(document).ready(function(){
$('ul').each(function(){
// get current ul
var $ul = $(this);
// get array of list items in current ul
var $liArr = $ul.children('li');
// get lenth of the array
var arrLen = $liArr.length;
// sort array of list items in current ul randomly
var $newArr = [];
do{
// Generate a randomize int
var rndNumber = parseInt(Math.random() * arrLen);
// Extract a element to add it into new Array
$newArr.push($liArr.slice(rndNumber,1));
// Remove the element from the array
$liArr.splice(rndNumber, 1);
// Decrement the length array
arrLen--;
}
while(arrLen >= 0);
// Add new table
$(this).append($newArr);
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!