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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:40:15+00:00 2026-06-09T02:40:15+00:00

My Jquery: function myTimer() { var sec = 15 var timer = setInterval(function() {

  • 0

My Jquery:

function myTimer() {
    var sec = 15
    var timer = setInterval(function() { 
    $('#timer').text(sec--);
    if (sec == -1) {
      clearInterval(timer);
      alert('done');
     } 
    }   , 1000);

}

$("#knap").click(function() {
    myTimer();
});

$("#reset").click(function() {
// set timer to 15 sec again.. 
});

I want the timer to be reset when clicked on #reset.

  • 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-09T02:40:17+00:00Added an answer on June 9, 2026 at 2:40 am

    You need to leave your “timer” variable in a scope that is available the next time you call the myTimer function so you can clear the existing interval and reset it with a new interval. Try:

    var timer;
    functionn myTimer() {
        var sec = 15
        clearInterval(timer);
        timer = setInterval(function() { 
        $('#timer').text(sec--);
        if (sec == -1) {
          clearInterval(timer);
          alert('done');
         } 
        }   , 1000);
    
    }
    
    $("#knap").click(function() {
        myTimer();
    });
    
    $("#reset").click(function() {
       myTimer();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My jQuery function is this: $(function() { $('#small').click(function() { var selectedRB = $('input[name=radioGroup]:checked').val(); alert(selectedRB);
I have a basic jQuery function going on: $(#selector).click(function(){ $(#target).append(Some text to be added...);
I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
Here's a JQuery function: $(label[for='ch_c'], label[for='ch_ad']).click( function(){ if( $(this).hasClass('active') ){ $('#box').fadeIn(300); } else {
jQuery(function($) { // create a convenient toggleLoading function var toggleLoading = function() { $(#loading).toggle()
My jQuery function looks like that $('input[type=text]').focus(function() { $(label).css(border-bottom-color, red); }); $('input[type=text]').blur(function() { $(label).css(border-bottom-color,
my a click jquery function is not working, it just doesn't give any errors
I am using jquery function which changes the class of element $(a).click(function(){ $(this).closest(ul).find(a).parent().removeClass(active); $(this).parent().addClass(active);
jQuery(function () { $('#square a').click(function(e) { // How is the e object structured });
I have the following jquery: function GetSelectedCheckboxIds(className) { var ln = className.length; return $('.'

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.