JSFiddle - React, Tailwind, and code Playground
by Asif Sharif Shahid
HTML
<div class="shuffledv">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div class="shuffledv">
<div>4</div>
<div>5</div>
<div>6</div>
</div>
JavaScript
(function () {
"use strict";
// Cycle over each .shuffledv HTMLElement
$(".shuffledv").each(function () {
// Remove all divs within, store in $d
var $d = $(this).find("div").remove();
// Sort $d randomnly
$d.sort(function () { return Math.floor(Math.random() * $d.length); });
// Append divs within $d to .shuffledv again
$d.appendTo(this);
});
}());