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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:24:44+00:00 2026-06-12T12:24:44+00:00

I am trying to make a fairly simple grid game where users have to

  • 0

I am trying to make a fairly simple grid game where users have to click tiles to reveal content underneath. The first issue i’m struggling with is implementing a click function that would remove not only the tile clicked but also a few tiles around it, preferably random.

My current code:

        $('.layer img').click(function() {
            $(this).css ('display', 'none');
        });

Any help extending my simple code much appreciated.

  • 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-12T12:24:45+00:00Added an answer on June 12, 2026 at 12:24 pm

    You can count the siblings and randomly hide some of them, like so:

    $('.layer img').click(function() {
         sib = $(this).siblings();
         rand = Math.floor((Math.random()*sib.length)+1);
         for (i=0;i<rand;i++) {
            sib.eq(i).css ('display', 'none');
         }
         $(this).css ('display', 'none');
    });
    

    I’m adding here enhanced version, as OP commented, to randomly select previous or next siblings, up to 5 five of them in total:

    $('.layer img').click(function() {
             sib = $(this).siblings();
             rand = Math.floor((Math.random()*sib.length)+1);
             rand = Math.min(5,rand);
             aprev = $(this);
             anext = $(this);
             for (i=0;i<rand;i++) {
                if (Math.floor((Math.random()*2)+1) == 1 ) { //random go prev or next
                   if (aprev.prev().length) {
                      aprev = aprev.prev();
                      aprev.css ('display', 'none');
                   } else {
                      anext = anext.next();
                      anext.css ('display', 'none');
                   }
                } else {
                   if (anext.next().length) {
                      anext = anext.next();
                      anext.css ('display', 'none');
                   } else {
                      aprev = aprev.prev();
                      aprev.css ('display', 'none');
                   }
                }
             }
             $(this).css ('display', 'none');
        });
    

    the code grew a bit because we have to control whether there are no more previous or next siblings, and in that case revert to the other.

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

Sidebar

Related Questions

I have a fairly simple problem. I'm trying to make a function that accepts
I have a fairly simple call I'm trying to make to a database. I
I'm fairly new to PHP and have been trying to make a simple login
I am fairly new to iOS development and trying make a simple app which
I'm trying to implement what I think is a fairly simple design. I have
I have been trying to create a fairly simple application in WPF following the
I'm trying to make a fairly simple image slideshow to replace a flash based
I'm trying to make a dynamically sizable title banner, using fairly simple image tricks.
I am trying to make a fairly simple call using PICC18. Using the MPLAB
I am trying to make a fairly simple navigation for a number of pictures

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.