Skip to content

Instantly share code, notes, and snippets.

@danbee
Created February 19, 2015 15:29
Show Gist options
  • Save danbee/11cac544172ae8e1b2d7 to your computer and use it in GitHub Desktop.
Save danbee/11cac544172ae8e1b2d7 to your computer and use it in GitHub Desktop.
// Add a function to jQuery to randomise selectors
$.fn.randomize = function(selector){
(selector ? this.find(selector) : this).parent().each(function(){
$(this).children(selector).sort(function(){
return Math.random() - 0.5;
}).detach().appendTo(this);
});
return this;
};
$(function () {
// Randomise li elements
$('ul.members').randomize('li');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment