JSFiddle - React, Tailwind, and code Playground

by juErik

HTML

<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<div>test 1</div>
<div>test 2</div>
<div>test 3</div>
<div>test 4</div>
<div>test 5</div>

JavaScript

(function($){
    /*
     *  Diese function mischt Elemente auf der Dom- Ebene
     *
        // Shuffle all list items within a list:
        $('ul#list li').shuffle();

        // Shuffle all DIVs within the document:
        $('div').shuffle();

        // Shuffle all <a>s and <em>s:
        $('a,em').shuffle();
    */

    $.fn.shuffle = function() {

        var allElems = this.get(),
            getRandom = function(max) {
                return Math.floor(Math.random() * max);
            },
            shuffled = $.map(allElems, function(){
                var random = getRandom(allElems.length),
                    randEl = $(allElems[random]).clone(true)[0];
                allElems.splice(random, 1);
                return randEl;
           });

        this.each(function(i){
            $(this).replaceWith($(shuffled[i]));
        });

        return $(shuffled);

    };

})(jQuery);

$('div').shuffle();