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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:55:04+00:00 2026-06-11T12:55:04+00:00

I got this function that starts a timer on this format 00:00:00 whenever I

  • 0

I got this function that starts a timer on this format 00:00:00 whenever I click on a button. But I don’t know how to do functions resume and pause. I’ve found some snippets that I thought could be helpful but I couldn’t make those work. I’m new to using objects in js.

function clock() {
  var pauseObj = new Object();

  var totalSeconds = 0;
  var delay = setInterval(setTime, 1000);

  function setTime() {
    var ctr;
    $(".icon-play").each(function () {
      if ($(this).parent().hasClass('hide')) ctr = ($(this).attr('id')).split('_');
    });

    ++totalSeconds;
    $("#hour_" + ctr[1]).text(pad(Math.floor(totalSeconds / 3600)));
    $("#min_" + ctr[1]).text(pad(Math.floor((totalSeconds / 60) % 60)));
    $("#sec_" + ctr[1]).text(pad(parseInt(totalSeconds % 60)));
  }
}

pad() just adds leading zeros

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

    I think it will be better if you will create clock object. See code (see Demo: http://jsfiddle.net/f9X6J/):

    var Clock = {
      totalSeconds: 0,
    
      start: function () {
        var self = this;
    
        this.interval = setInterval(function () {
          self.totalSeconds += 1;
    
          $("#hour").text(Math.floor(self.totalSeconds / 3600));
          $("#min").text(Math.floor(self.totalSeconds / 60 % 60));
          $("#sec").text(parseInt(self.totalSeconds % 60));
        }, 1000);
      },
    
      pause: function () {
        clearInterval(this.interval);
        delete this.interval;
      },
    
      resume: function () {
        if (!this.interval) this.start();
      }
    };
    
    Clock.start();
    
    $('#pauseButton').click(function () { Clock.pause(); });
    $('#resumeButton').click(function () { Clock.resume(); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know why, but this function is going in the loop under Timer,
I've got an object with functions that throw errors, myObj = { ini:function(){ this.f();
In the end, I got this function. I don't know whether it's normal or
I've got a .js file that has this function in it: function showDialog(divID) {
I've got this code in the InitInstance function of a class that extends WinApp:
I've got a set up that, in stylised form, is like this: (function ()
I've got a javascript function I created. Somewhere in that function, this line is
I got this function to split string but it's giving the spited string in
So I've got a text input that get's date & time in this format:
I have a timer function I got off this site and have tried to

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.