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

  • Home
  • SEARCH
  • 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 8576329
In Process

The Archive Base Latest Questions

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

I want to make a countdown timer, that can be used on several places

  • 0

I want to make a countdown timer, that can be used on several places in the same page – so I think it should be a function in some way.

I really want it to be made with jQuery, but I cant quite make it happen with my code. I have e.g. 10 products in a page, that I need to make a countdown timer – when the timer is at 0 I need it to hide the product.

My code is:

$(document).ready(function(){

    $(".product").each(function(){

        $(function(){
            var t1 = new Date()
            var t2 = new Date()
            var dif = t1.getTime() - t2.getTime()

            var Seconds_from_T1_to_T2 = dif / 1000;
            var Seconds_Between_Dates = Math.abs(Seconds_from_T1_to_T2);

            var count = Seconds_Between_dates;
            var elm = $(this).attr('id');
            alert(elm);
            countdown = setInterval(function(){
                $(elm + " .time_left").html(count + " seconds remaining!");
                if (count == 0) {
                    $(this).css('display','none');
                }
                count--;
            }, 1000);
        });
    });
});

EDIT 1:

$(document).ready(function(){

    $(".product").each(function(){
            var elm = $(this).attr('id');           

        $(function(){
            var t1 = new Date()
            var t2 = new Date()
            var dif = t1.getTime() - t2.getTime()

            var Seconds_from_T1_to_T2 = dif / 1000;
            var Seconds_Between_Dates = Math.abs(Seconds_from_T1_to_T2);

            var count = Seconds_Between_dates;

            alert(elm);
            countdown = setInterval(function(){
                $(elm + " .time_left").html(count + " seconds remaining!");
                if (count == 0) {
                    $(this).css('display','none');
                }
                count--;
            }, 1000);
        });
    });
});

Do you have any solutions to this?

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

    I’d probably use a single interval function that checks all the products. Something like this:

    $(function() {
    
        /* set when a product should expire.
           hardcoded to 5 seconds from now for demonstration
           but this could be different for each product. */
        $('.product').each(function() {
            $(this).data('expires', (new Date()).getTime() + 5000);
        });
    
        var countdown_id = setInterval(function() {
            var now = (new Date()).getTime();
            $('.product').each(function() {
                var expires = $(this).data('expires');
                if (expires) {
                    var seconds_remaining = Math.round((expires-now)/1000);
                    if (seconds_remaining > 0) {
                        $('.time-left', this).text(seconds_remaining);
                    }
                    else {
                        $(this).hide();
                    }
                }
            });
        }, 1000);
    });
    

    You could also cancel the interval function when there is nothing left to expire.

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

Sidebar

Related Questions

I'm want to make a countdown timer that return value(seconds left) when a touch
I want to make a countdown timer in C#, WinForms. I want to be
i want to set textview text in alertbox. I want to make the countdown
I want make interactive application where user launches it and can do various task
Let's say I want make some of my sources publicly available via my blog
I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I have an underlying asynchronous out-of-order query/response system that I want to make synchronous.
I tried to make a countdown with the NSTimeInterval. But I want to be
I am trying to make a timer for my game that counts down from
I want to make a background application in countdowntimer, that is if i am

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.