Last Updated: February 25, 2016
·
2.325K
· joseluisq

Shuffle child elements with jQuery

jQuery.fn.shuffleChildren = function(){
    var p = this[0];
    for (var i = p.children.length; i >= 0; i--) {
        p.appendChild(p.children[Math.random() * i | 0]);
    }
};

Usage:

$('ul').shuffleChildren();