Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:22:50+00:00 2026-05-31T10:22:50+00:00

I would like to implement a shuffle function, I have this piece of code

  • 0

I would like to implement a shuffle function, I have this piece of code which worked when the images were not in a table –

var a = $("#deck > div").remove().toArray();
for (var i = a.length - 1; i >= 1; i--) {
    var j = Math.floor(Math.random() * (i + 1));
    var bi = a[i];
    var bj = a[j];
    a[i] = bj;
    a[j] = bi;
}
$("#deck").append(a);

and this is the code – http://jsfiddle.net/kommandoss/YuRpU/39/

any help appreciated, thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:22:51+00:00Added an answer on May 31, 2026 at 10:22 am

    Here is a working jsiddle. I added ids to the parent divs like id=”0″ … id=”7″. I also added a class=”letter” in order to be able to count the amount of images and use it within the calculation. The code basically just loops through 36 times and switches 2 random letters with one another within 2 random divs:

    <table border="1">
    <tr>
        <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event);" id="0">
                <img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-A-dg-icon.png" ondragstart="drag(event);" id="a" draggable="true" class="letter"/>
            </div>
        </td>
       <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)" id="1"><img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-B-dg-icon.png"  ondragstart="drag(event);" id="b" draggable="true"/> </div>
        </td>
       <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)" id="2"><img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-C-dg-icon.png"  ondragstart="drag(event);" id="c" draggable="true" class="letter"/> </div>
        </td>
    </tr>
    
    <tr>
        <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)" id="3"><img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-D-dg-icon.png"  ondragstart="drag(event);" id="d" draggable="true"/> </div>
        </td>
        <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)" id="4"><img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-F-dg-icon.png"  ondragstart="drag(event);" id="f" draggable="true" class="letter"/> </div>
        </td>
       <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)" id="5"><img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-G-dg-icon.png"  ondragstart="drag(event);" id="g" draggable="true" class="letter"/> </div>
        </td>
    </tr>
    
    <tr>
        <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)" id="6"><img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-H-dg-icon.png"  ondragstart="drag(event);" id="h" draggable="true" class="letter"/> </div>
        </td>
       <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)" id="7"><img src="http://icons.iconarchive.com/icons/hydrattz/multipurpose-alphabet/128/Letter-I-dg-icon.png"  ondragstart="drag(event);" id="i" draggable="true" class="letter"/> </div>
        </td>
      <td>
            <div ondrop="drop(event);" ondragover="allowDrop(event)"> </div>
        </td>
    </tr>
    

    ​

    function shuffleLetters()
    {
        var amount = $('.letter').length;
        var foundSix = false;
        var x;
        for(x = 0; x < 36; x++) {
            var randomNum1 = Math.round(Math.random()*amount);
    
            if(randomNum1 == 6 && !foundSix)
            {
                randomNum1 = 7;
                foundSix = true;
            }
            var randomNum2 = Math.round(Math.random()*amount);
            var randomHtml1 = $("#"+randomNum1).html();
            var randomHtml2 = $("#"+randomNum2).html();
            $("#"+randomNum1).html(randomHtml2);
            $("#"+randomNum2).html(randomHtml1);
        }
    }
    
    $(function () {
        shuffleLetters();
    });
    

    http://jsfiddle.net/YuRpU/52/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement a table in JSP page which is something similar
i would like to implement a function in R which is able to increase
I would like to implement a command line interface for a Java application. This
I would like to implement a method like this: boost::unique_future<int> foo() { return defer([=]
I would like to implement a function that takes as input a size n
I would like to implement a save feature, which allows my users to save
I would like to implement an algorithm which will find the bounding rectangles of
I would like implement next sceario: I've got a wi-fi router, which can be
I would like to implement a URL rewrriter for DotNetNuke. Have questions as to
I would like to implement a high-traffic restful .NET 4.0 WCF service which can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.