I have several divs which content must often be randomized and back to their regular order within each of those divs.
I use a function like the one below for each one of those divs, with different class for each div, randomizing perfectly each div on page load. The random function works great, but I need to know how to get each div back to normal order by clicking a button and then back to any random order again, and I suppose it could be done by using jQuery's toggle method.
<script>
$(function () {
var parent = $(".randomONE");
var divs = parent.children();
while (divs.length) {
parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);
}
});
</script>
Thanks to all in advance!
Aucun commentaire:
Enregistrer un commentaire