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 605125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:06:44+00:00 2026-05-13T17:06:44+00:00

I am trying to get a random cell in jquery, between 1-16, I have

  • 0

I am trying to get a random cell in jquery, between 1-16, I have the random number code in Javascript. Now what I want to do is to use that random number, and make the pointer of the table go to that random number? How would this be accomplished. Here is my random number code.

    Math.floor(Math.random() * 16)

    <table id="board" border="3" bgcolor="black"  align="center">
      <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
    </table>
    <input type="button" value="Shuffle" onclick="shuffle()"/>
    </body>
</html>

What I actually should have said is reference, I want to get a reference to a random cell by using the random generator code in javascript

$('board tr td')

That should give me some way of entry in the table

  • 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-13T17:06:45+00:00Added an answer on May 13, 2026 at 5:06 pm

    A jQuery specific solution is to assign a click event to the button in javascript, and put FiveTools code solution there.

    <input type="button" value="Shuffle" id="theButton"/>
    

    javascript:

    $('document').ready(function() {
    
    $('#theButton').click(function() {
    
        // Stores a random number from 0 to 15
        var randomNum = Math.floor(Math.random() * 16);
    
        // This brings you back up to a range of 1 to 16
        var actualNum = randomNum + 1;
    
        // Grabs and holds the table cell for that number
        // Example: number 10 would be third row, second column
        var randomtd = $('#board td').eq(randomNum);
    
        // Calculate and store which row
        // by dividing the generated number by the number of rows, and rounding up
        var whichRow = Math.ceil(actualNum / 4);
    
        // Calculate and store which column
       // by using modulo to find the remainder of the number divided by the rows
       // If the modulo result is '0', then set it to '4'
        var whichColumn = (actualNum % 4) == 0 ? 4 : (actualNum % 4);
    
        // Display results in an alert
        alert('theNumber: ' + actualNum + ' row: ' + whichRow + '  column: ' + whichColumn);
    
       // For fun, and to show that you have the td stored
       // Display the number in the correct td
       // and set the text color to grey, since the table is black
       randomtd.text(actualNum).css({color:'#DDD'});
    });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get random number between -5 and 5. Im using this code:
I have a float and I am trying to get a random number between
I am trying to get a random number generator that will be biased in
I'm trying to get random numbers between 0 and 100. But I want them
I've struggled with this all day, I am trying to get a random number
Hi im trying to get a uniform random number generator using a crypto algorithm
I am trying to get a random color. I have done it using brute
I've been trying to get a better grasp on jQuery and have been coming
I am trying to get a random year between 1900 and 1980 with Ruby.
I'm trying to get a random number generator working on the iPhone. There are

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.