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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:12:54+00:00 2026-06-01T13:12:54+00:00

I made a countdown timer and coded this in with HTML and CSS, but

  • 0

I made a countdown timer and coded this in with HTML and CSS, but I wasn’t able to make it functional using jQuery. How can I functionalize this countdown? Here is the HTML structure I prefer the countdown to be in:

    <div id="counter-container">
      <div class="counter-box">
        <div class="counter"><p class="counter-p">#</p></div>
        <p class="counter-box-p">days</p>
      </div>
      <div class="counter-box">
        <div class="counter"><p class="counter-p">#</p></div>
        <p class="counter-box-p">hours</p>
      </div>
      <div class="counter-box">
        <div class="counter"><p class="counter-p">#</p></div>
        <p class="counter-box-p">minutes</p>
      </div>
      <div class="counter-box">
        <div class="counter"><p class="counter-p">#</p></div>
        <p class="counter-box-p">seconds</p>
      </div>

As you can see, I have already added paragraph elements for days, hours etc, therefore I do not want to embed any extra text through jQuery.

P.S. Could anyone please tell me how to set a new countdown date?

  • 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-01T13:12:56+00:00Added an answer on June 1, 2026 at 1:12 pm
    function counter(count) {
      countdown = setInterval(function(){
        var temp;
        $("p#d").html(Math.floor(count/(60*60*24)));
        temp = count%(60*60*24);
        $("p#h").html(Math.floor(temp/(60*60)));
        temp = count%(60*60);
        $("p#m").html(Math.floor(temp/(60)));
        temp = count%(60);
        $("p#s").html(temp);
        if (count == 0) {
             alert("time's up");
             clearInterval(countdown);       
        }
        count--;
      }, 1000);
    }
    
    counter(60*60*24*2);
    

    ​demo

    EDIT-1:

    counter gets time as seconds.

    counter(10); //10 seconds
    counter(10*60) //600 seconds -> 10 minutes.
    counter(10*60*60) //36000 seconds -> 600 minutes -> 10 hour
    

    EDIT-2:

    if you want it to work Date based, you should change function like this,

    function counter(futureDate) {
      var today = new Date(); // today
      count = Math.floor((futureDate-today)/1000);
      countdown = setInterval(function(){
        var temp;
        $("p#d").html(Math.floor(count/(60*60*24)));
        temp = count%(60*60*24);
        $("p#h").html(Math.floor(temp/(60*60)));
        temp = count%(60*60);
        $("p#m").html(Math.floor(temp/(60)));
        temp = count%(60);
        $("p#s").html(temp);
        if (count == 0) {
             alert("time's up");
             clearInterval(countdown);       
        }
        count--;
      }, 1000);
    }
    
    counter(new Date(2012,4,8)); // May 8, 2012 00:00:00
    /* counter(new Date(2012,4,8,15,49,10)); // May 8, 2012 15:49:00 */
    ​
    

    http://jsfiddle.net/NfLAB/1/

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

Sidebar

Related Questions

I have made this timer script but I can't seem to make it so
Made a simple app which using a timer, counts the number of mouse clicks
I made an application in android and used timer like this.. try { CountDownTimer
I'm pretty new to all this. I've read through the forums, but can't seem
I have made separate project for countdown timer and it is working fine. Now
Made a much simpler example, hopefully someone can follow this and help me Here
Made solution change: I am trying to display a html table of data.. In
Made this nice little loop for hiding and showing div's, works as a charm
Made a fiddle for this: http://jsfiddle.net/terjeto/MN4FJ/ My problem is that dragleave fires when you
Made a new project, added main.cpp and wrote the code at this URL: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/example/echo/async_tcp_echo_server.cpp

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.