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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:21:39+00:00 2026-06-10T10:21:39+00:00

I am using a jQuery Based Memory Game on my site. You can restart

  • 0

I am using a jQuery Based Memory Game on my site. You can restart the game at anytime you like. Works great. Now I finish a game then I hit Play Again. If I hit restart it no longer works. Why and How do I fix it?

Here is a fiddle.

JS:

// this script shows how you can get info about the game
    var game = jQuery('div.slashc-memory-game'); // get the game
    var info = jQuery('p#info').find('span'); // get the info box
    var restart = jQuery('a#restart').css('visibility', 'visible'); // get the play again link
    var playAgain = jQuery('a#play-again').css('visibility', 'hidden'); // get the play again link
    // format time like hh:mm:ss
    var formatTime = function(s)
    {
        var h = parseInt(s / 3600), m = parseInt((s - h * 3600) / 60); s = s % 60;
        return (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s);
    }
    // listen for game 'done' event 
    game.bind('done', function(e)
    {
        // show basic stats
        var stats = game.slashcMemoryGame('getStats');
        info.html('Success ! Number of clicks : ' + stats.numClicks + ', elapsed time : ' + formatTime(parseInt(stats.time / 1000)) + '.');
        playAgain.css('visibility', 'visible'); // show link
        restart.css('visibility', 'hidden'); // show link
    });
            // Restart action
    restart.click(function(e)
    {
        game.slashcMemoryGame('restart'); // restart game
    });
    // play again action
    playAgain.click(function(e)
    {
        playAgain.css('visibility', 'hidden'); // hide link
        info.html('Memory Game, click to reveal images. <a id="restart" href="#">Restart</a>'); // reset text
        game.slashcMemoryGame('restart'); // restart game
        e.preventDefault();
    });

HTML:

<p id="info"><span>Memory Game, click to reveal images. <a id="restart" href="#">Restart</a></span> <a id="play-again" href="#">Play Again</a></p>
  • 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-10T10:21:40+00:00Added an answer on June 10, 2026 at 10:21 am

    You’re replacing the #restart element whenever you click #play-again at this line:

    info.html('Memory Game, click to reveal images. <a id="restart" href="#">Restart</a>');
    

    This means the click handler for the #restart element is no longer attached to the new element.

    You should attach the handler to an ancestor element which is always present in the DOM using a delegated event handler .on():

    info.on('click', '#restart', function(e)
    {
        game.slashcMemoryGame('restart'); // restart game
    });
    

    Fiddle

    I replaced the #restart element’s directly-bound event handler with a delegated event handler. Here’s the reference for an extra read: Direct and delegated events. Basically, you can only bind event handlers to elements currently in the DOM, and:

    Delegated events have the advantage that they can process events from descendant elements that are added to the document at a later time.

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

Sidebar

Related Questions

I am using a jquery based rich text editor lwRTE It works well in
I am using jQuery now to dynamically generate DIVs based off user input. With
I'm using a flash/ajax file upload in php based on this site - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/
By using jquery ajax function, I can do something like: $.ajax({ url: url, type:
Using jQuery, I'd like to display a different set of text based on a
Using jquery, i would like to remove a hidden input, based on a class
I want to make a jQuery based custom popup window for my site using
I created a page that has a JQuery based dialog using the standard JQuery
I am using jquery to duplicate several html fields based on user's selection. However,
I am working with a touch based slideshow for the iPad using Jquery tools

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.