Last active
August 29, 2015 14:03
-
-
Save fieldoffice/e1ecc9e0ee8e3fe7f376 to your computer and use it in GitHub Desktop.
Randomise a group of divs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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