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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:23:40+00:00 2026-06-03T05:23:40+00:00

I’m trying to create a game of memory using Javascript/jQuery. Basically, a random array

  • 0

I’m trying to create a game of memory using Javascript/jQuery. Basically, a random array is generated at the beginning of each game, and the user’s task is to match sets of letters. I’m having trouble selecting individual letters from the array.

Here’s a link to a working example on jsfiddle, but the relevant parts are below:

Here’s the html that the array is inserted into:

<div id="game"></div>

Right now, I’m just trying to implement a hover function that changes the background color of the letter. Here’s the CSS:

.hover
{
  background-color: #A6977B;
}

Here’s the Javascript that generates the array:

function generateBoxes(gameSize, lettersSize) { 
  var currentLetter;
  letters = randomizeArray(lettersSize);
  rows = gameSize/columns; 
  for (var i=0; i<rows; i++) {
    var row = $("<div class='row'></div>");
    $("#game").append(row);
    for (var n=0; n<columns; n++) {
      currentLetter = letters[5*i + n];
      row.append("<div class='column displayNone' id = 'r" + i + "c" + n + "'>" + currentLetter + "</div>");
    }
  }

};

Here’s the Javascript for the hover function:

  $("#game").hover(function() {
    $(this).toggleClass("hover");
  }); 

This Javascript code for the hover function works to select all the letters within the array. I only want to select one at a time, however. I’ve tried replacing #game with:

  • #game div
  • #game .row .column
  • .column

None of those options work to select just one letter (in fact, when I use anything besides just #game, the hover function isn’t called at all).

What is the correct way to select child divs by class here?

Edit: Here is the generated html:

<div id="game"> 
  <div class="row">
    <div class="column displayNone" id="r0c0">E</div>
    <div class="column displayNone" id="r0c1">D</div>
    <div class="column displayNone" id="r0c2">E</div>
    <div class="column displayNone" id="r0c3">D</div>
    <div class="column displayNone" id="r0c4">B</div>
  </div>
  <div class="row">
    <div class="column displayNone" id="r1c0">A</div>
    <div class="column displayNone" id="r1c1">C</div>
    <div class="column displayNone" id="r1c2">C</div>
    <div class="column displayNone" id="r1c3">A</div>
    <div class="column displayNone" id="r1c4">B</div>
  </div>
</div>
  • 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-06-03T05:23:41+00:00Added an answer on June 3, 2026 at 5:23 am

    Since you’re generating your letter divs dynamically, you’ll want to bind the mouseenter and mouseleave events to the divs using jQuery’s .on() function. Try this:

    $('#game').on('mouseenter', 'div.column', function() {
        $(this).toggleClass("hover")
    }).on('mouseleave', 'div.column', function() {
        $(this).toggleClass("hover")
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.