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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:25:15+00:00 2026-05-26T02:25:15+00:00

I’m missing some fundamental understanding of javascript function flow control… I’ve created a jquery

  • 0

I’m missing some fundamental understanding of javascript function flow control…

I’ve created a jquery slideshow. The show is broken down into logical sections, each section is controlled by a function (makes it easy to add sections later)…

function myslideshow() {
    section1();
    section2();
    section3();
}

Each section has multiple functions composed of jquery statements, animations, timed stuff…so maybe..

function section1() {
    firstPart();
    setTimeout('secondPart()',5000);
    setTimeout('thirdPart()',6000);
}

Now here’s my issue… I want to define the functions “firstPart(), secondPart(), thirdPart()” inside of section1(). I want to do this for various reasons:

  1. Each section may logically have their own “parts”
  2. Portability of the section

So I would like to keep the section and all of its respective parts inside of the section.

I can’t seem to get it to work… when I define “parts” inside of the section all of the functions are ran at the same time.

so ideally what I’d like to have is:

function section1() {
    firstPart();
    setTimeout('secondPart()',5000);
    setTimeout('thirdPart()',6000);

    function firstpart(){  
         //some code here
    }

    function secondPart(){  
         //some code here
    }

    function thirdPart(){  
         //some code here
    }

}

But again that doesn’t work out properly; actually it works properly I’m just not implementing it properly! Not sure if I need to leverage function callbacks (not even sure how to set that up in a “scalable manner”).

Another area for improvement: setTimeouts are used to ensure the secondPart runs after the firstPart… wondering if there are better ways to “wait” on the previous function (with jquery animations) to complete.

I appreciate any direction that you can offer. Thanks!

  • 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-26T02:25:15+00:00Added an answer on May 26, 2026 at 2:25 am

    You’re calling “setTimeout()” incorrectly:

    setTimeout(secondPart, 5000);
    

    That will pass a reference to your local function. When you pass a string, the runtime system will evaluate it when the timer goes off, in the global context. Thus, it won’t find your local function.

    As to your last question, most (if not all) jQuery animation routines allow a function to be passed as the last argument. The function is run after the animation completes. Again, in such cases, you should pass a reference to your function and not a string containing a function call expression. (I doubt that would work with jQuery anyway.)

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.