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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:55:40+00:00 2026-05-22T17:55:40+00:00

Possible Duplicate: How to pause a setTimeout call ? I have a function that

  • 0

Possible Duplicate:
How to pause a setTimeout call ?

I have a function that gets called on page load which starts off a repeating function:

        setTimeout(function () {
            repeat();
        }, 8000)

This function calls repeat() every 8 seconds, inside this function I have a bit of ajax which updates a counter on the page. Clicking on the counter gives the user a drop down menu with a number of messages. The counter value equals the number of messages the user has. Kind of like Facebook notifications.

When clicking the drop down menu Im using jQuery to hide and show it:

  $('#messages').click(function () {
        $('#messagesDropDown').slideDown();
    })
    .mouseleave(function () {
        $('#messagesDropDown').slideUp();
    });

When the #messagesDropDown is visible I want to stop the repeat() function, to prevent the list of messages from updating while Im viewing the current ones.

On .mouseleave I want to start the repeat() function again.

Anyone have any ideas how I can ‘STOP’ a repeating function In the .click function and start it again on .mouseleave ?

  • 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-22T17:55:40+00:00Added an answer on May 22, 2026 at 5:55 pm

    You said that this code starts a repeating function:

    setTimeout(function () {
        repeat();
    }, 8000)
    

    Since setTimeout doesn’t repeat, I assume that the repeat function itself fires off another setTimeout to call itself again after it runs (chained setTimeout calls).

    If so, you have two options:

    1. Have a control variable telling repeat whether to do its work or not. A simple boolean will do. Set the boolean when you want repeat to skip its work, and have repeat check it. This is the dead simple answer.

    2. Have control functions for repeat, like so:

      var repeatHandle = 0;
      function startRepeat() {
          if (!repeatHandle) {
              repeatHandle = setTimeout(repeatTick, 8000);
          }
      }
      function repeatTick() {
          repeatHandle = 0;
          repeat();
      }
      function stopRepeat() {
          if (repeatHandle) {
              clearTimeout(repeatHandle);
              repeatHandle = 0;
          }
      }
      

      …and then use them to control the repeats. Be sure to modify repeat to call startRepeat to schedule its next call rather than calling setTimeout directly.

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

Sidebar

Related Questions

Possible Duplicate: getDate with Jquery Datepicker I have a registration page inside that I
Possible Duplicate: javascript: pause setTimeout(); Im using jQuery and working on a notification system
Possible Duplicate: How to detect if JavaScript is disabled? I have a website which
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible duplicate question: Is there a way to indefinitely pause a thread? In my
Possible Duplicate: Parse multiple doubles from string in C# Say I have a line
Possible Duplicate: how to parse hex or decimal int in Python i have a
Possible Duplicate: Best XML Parser for PHP I have a string with XML data

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.