
JavaScriptでHTMLの要素をシャッフル
ギャラリー?を作っていてDOMのシャッフルがしたくなったのでメモ。
let target = document.querySelector("section");
for(let i=target.children.length;i>=0;i--){
target.appendChild(target.children[Math.random()*i|0]);
}
ギャラリー?を作っていてDOMのシャッフルがしたくなったのでメモ。
let target = document.querySelector("section");
for(let i=target.children.length;i>=0;i--){
target.appendChild(target.children[Math.random()*i|0]);
}