Skip to content

Instantly share code, notes, and snippets.

@fieldoffice
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fieldoffice/e1ecc9e0ee8e3fe7f376 to your computer and use it in GitHub Desktop.
Save fieldoffice/e1ecc9e0ee8e3fe7f376 to your computer and use it in GitHub Desktop.
Randomise a group of divs
$(document).ready(function() {
$('.rdm').hide();
var elements = $('.rdm');
var elementCount = elements.size();
var elementsToShow = 5;
var alreadyChoosen = ",";
var i = 0;
while (i < elementsToShow) {
var rand = Math.floor(Math.random() * elementCount);
if (alreadyChoosen.indexOf("," + rand + ",") < 0) {
alreadyChoosen += rand + ",";
elements.eq(rand).show();
++i;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment