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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:16:27+00:00 2026-06-04T00:16:27+00:00

In a simple setInterval setInterval(function() { // Do something every 9 seconds }, 9000);

  • 0

In a simple setInterval

setInterval(function() {
      // Do something every 9 seconds
}, 9000);

The first action will happen after 9 seconds (t=9s). How to force the loop to perform the first action immediately (t=0)?

I think it is due to the mechanism of setInterval to have Delay - Action - Delay - Action ... loop; instead of Action - Delay - Action - Delay ... loop.

EDIT: My function is indeed a loop as

setInterval(function(){
$('.test').each(function(idx){
    var duration = 1000;
    $(this).delay(duration*idx);
    Some stuff here
});
}, 4000);
  • 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-04T00:16:28+00:00Added an answer on June 4, 2026 at 12:16 am

    Keep it simple. You can use a named function instead of an anonymous function; call it and set an interval for it.

    function doSomething() {
        console.log("tick");
    }
    doSomething();
    setInterval(doSomething, 9000);
    

    Create a scope if necessary:

    (function() {
        function doSomething() {
            console.log("tick");
        }
        doSomething();
        setInterval(doSomething, 9000);
    })();
    

    Finally, the following works without creating or affecting x:

    setInterval(function x() {
        console.log("tick");
        return x;
    }(), 9000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple system that refreshes a div every few seconds: $(document).ready(function() {
I'm using the simple jQuery DIV refresh code. var refreshId = setInterval(function() { $('#refreshdash').load('dashboard.php?cache=');
I have a very simple problem in which I need to do something after
$('#scrollbar1').css('width','1000px'); $('#scrollbar1 img').css('width','980px'); setInterval(function(){ var ff = $('#scrollbar1 img:first'); var ll = $('#scrollbar1 img:last');
I have built an uploader for my application but struggling on something. Every 3
Ive been writing a simple jquery function that turns a div with a list
I'm starting with socket.io with a simple exemple : Client Side : $(document).ready(function ()
Imagine you have a simple function in Windows Script Host (JScript) environment: function say(text)
I'm building a simple Facebook tab. I have two tabs that change every 3
I have some simple code: function testing(){ for (a=1; a<=4; a++) { this[btn+a].enabled =

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.