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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:53:44+00:00 2026-05-28T18:53:44+00:00

I have the following function: $(document).ready(function() { $(‘#p’).click(function() { $(‘#s1’).hide(); gameStart(); <-starts timer $(‘#s2’).show();

  • 0

I have the following function:

$(document).ready(function() {
    $('#p').click(function() {
        $('#s1').hide();
        gameStart(); <-starts timer
        $('#s2').show();
    });

    $('.b4').click(function() {
        clearInterval(tI); <-stops the time
    });
    $('#r').click(function() {
        tI = setInterval("setTimer()", 1000); <-not working, should continue the timer again
    });
});

When the div #p is clicked it will start a game with a timer, this all works. Now if I click the div .b4 it will stop/pauze the timer, this also works. The problem is to start the timer again, continuing from where it was stopped.

I’ve tried tI = setInterval("setTimer()", 1000); when clicking the div #r but the problem with this is that is will start the timer, but it will not continue from the time it was stopped. It will continue, but from the time where it should be if it wasn’t stopped/pauzed.

SO how can I fix this? I want to pause the time (think I have this part right) and then continue it again when clicking #r

This is how my timer function is build:

function gameStart() {
    setBlocks();
    tM = $('#a1 div.tm');
    hS = $('#a1 div.hs');
    oT = new Date();
    tI = setInterval("setTimer()", 1000);
    setHs();
    $('.ht').click(hint);
    $('.b3').click(reset);
}


//Set timer
function setTimer() {
    var n = new Date();
    tM.text(getTimeText(n.getTime() - oT.getTime()));
}

//Build timer
function getTimeText(v) {
    var vH = Math.floor(v / 3600000);
    var vM = Math.floor((v - (vH * 3600000)) / 60000);
    var vS = Math.floor((v - (vH * 3600000) - (vM * 60000)) / 1000);
    return set2Digit(vH) + ':' + set2Digit(vM) + ':' + set2Digit(vS);
}

function set2Digit(ov) {
    var os = '0' + ov;
    return os.substr(os.length - 2, 2);
}

–EDIT–

With this html I get the time to show: <div class="tm">00:00:00</div>

–EDIT2–
Okay created a new function. It grabs the paused time, so from this point the time should continue:

$('#r').click(function() {
        $('#s1').hide();
        tI = setInterval("continueTimer()", 1000); //NEW
        $('#s2').show();
    });

//Test
function continueTimer() {
    divObj = document.getElementById("tm");
    tM.text(divObj.innerText);
}

At the moment, the time pauses but doesn’t continue when this function is fired… So how do I start the timer from this point? I think I am close

  • 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-28T18:53:45+00:00Added an answer on May 28, 2026 at 6:53 pm

    It is because in setTimer method you are creating a new Date object. So everytime this method executes it will take the current time. If you want to continue form where the timer was stopped instead of creating new Date object everytime, maintain the start date when the timer starts in a variable and then use that variable inside setTimer method.

    Modify the below method and add a global variable.

    var initialTime;
    function setTimer() {
        tM.text(getTimeText(initialTime.getTime() - oT.getTime()));
        initialTime.setMilliseconds(1000);
    }
    
    function gameStart() {
        setBlocks();
        tM = $('#a1 div.tm');
        hS = $('#a1 div.hs');
        oT = new Date();
        initialTime = new Date();
        setTimer();
        tI = setInterval("setTimer()", 1000);
        setHs();
        $('.ht').click(hint);
        $('.b3').click(reset);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code $(document).ready(function() { $('a#slick-toggle').click(function() { $('#slickbox0').toggle(400); return false; }); });
I have the following code: $(document).ready(function(){ $(.yearInner).hide(); $(.year, this).hover( function () { $(.yearInner, this).slideToggle();
I have the following code: $(document).ready(function () { $(tr).live('click',function(){ alert(TR); }); $(input).live('click',function(){ alert(INPUT); });
I have the following code: $(document).ready(function() { $(#TestLink).click(function() { $(#LinkHolder).html(test); }); }); <span id=LinkHolder>
I have the following code at JSfiddle: http://jsfiddle.net/ACG2D/ $(document).ready(function() { $('.testThis').click(function() { $('.regexValidation').each(function() {
I have the following code $(document).ready(function(){ // class exists if($('.delete').length) { // add click
I have the following: $(document).ready(function() { $(#select-all-teammembers).click(function() { $(input[name=recipients\\[\\]]).attr('checked', true); }); }); I'd like
I have the following function: jQuery(document).ready(function($){ $(div.findButton).click(function(){ UidID=Math.floor(Math.random()*1000); PostCode=$(#postcode).val(); $.get(result.php, {postcode: PostCode,uid:UidID}, function(response){ $(#result).html(response);
I have the following <script> $(document).ready(function() { $(.mapLink).click(function(){ pos = $(this).attr(id); alert(pos); }); });
I have the following function which works very well within a $(document).ready(function(){ $('.threadWrapper >

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.