This question already has an answer here:
- Randomize children elements on load 3 answers
I'm working on my first website (personal use for my portfolio). I have content in divs, but want them to reorder in randomly each time the page is reloaded. I tried to search for solutions, found a few similar questions, but didn't get anything to work (maybe it's because my content has multiple classes?).
what i have inside the body tags is is:
<div class="box work_self work_all">
<img src="1.jpg' />
</div>
<div class="box work_group work_all">
<img src="2.jpg' />
</div>
<div class="box work_group work_all">
<img src="3.jpg' />
</div>
[...]and so on.
Help is appreciated! Thanks!
Sorry for the late, response, I hope this still helps you. Here you have a live fiddle: http://jsfiddle.net/J5z4n/1/ and below you have the source code. You may replace 10 with another number bigger than your number of elements. The idea is to save the innerHTMLs of the target tags and then swap them.
The following will get them out of the dom and print them back out randomly.
Try this:
You can find shuffle() function here https://stackoverflow.com/a/6274398/2604607