• A
  • B
  • C ...">

    How to make tags randomly switch places?

    I have several tags <li>under one id, for example:

    <div id="myID">
        <li>A</li>
        <li>B</li>
        <li>C</li>
    </div>
    

    I would like them to randomly switch places when capsizing. I thought maybe with the Sortable jQuery effect? but not sure ... any help would be appreciated. Thank.

    +3
    source share
    3 answers

    accidentally?

    $('#myID').bind('mouseover', function(){
        $('#myID li').sort(function(){ return Math.random() - .5; }).each(
            function(){
                $('#myID').append(this);
            }
        );
    });
    
    +2
    source

    Here is a related blog post:

    +1
    source

    jquery-shuffle, mouseenter, "li" . http://mktgdept.com/js/jquery-shuffle.js?v0.0.1

    <div id="myID">
        <li>A</li>
        <li>B</li>
        <li>C</li>
    </div>
    
    <script type="text/javascript">
    $('#myID').mouseenter(function(){
    
        $('#myID li').shuffle();
    
    });
    </script>
    

    cwolves script, , mouseenter

    0

    All Articles