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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:05:31+00:00 2026-06-05T05:05:31+00:00

Normally the execution of a setTimeout() method is aborted by a clearTimeout() method that

  • 0

Normally the execution of a setTimeout() method is aborted by a clearTimeout() method that is outside of the setTimeout() method, but in my situation I need to abort the execution of a setTimeout() loop within the loop itself if a certain event occurs during the designated “waiting period”.

In my code shown below, the user gets 500 milliseconds to activate Code A. If he fails to activate Code A within the time frame, Code B will be executed as a fallback. Within Code A I have marked two places: 1) the place to stop the timeout and 2) the place where I wish to exit the function.

My jsFiddle is here.

A copy of my JavaScript and HTML codes is shown below:

HTML

<table id="headMenu">
    <tr>
        <td id="head1">Item 1</td>
        <td id="head2">Item 2</td>
        <td id="head3">Item 3</td>
    </tr>
</table>
<table id="subMenu">
    <tr>
        <td>Dynamic Content!</td>
    </tr>
</table​​​​​​​​​​​​​​​​​​​​​​​​​​​​>​​​

JavaScript

a = 500;
document.getElementById("head1").onmouseover = function(displayMenu) {
    document.getElementById("subMenu").innerHTML = "<tr><td>Item A</td><td>Item B</td><td>Item C</td></tr>";
    document.getElementById("head1").onmouseout = function(getScroll) {
        setTimeout(function() {
            document.getElementById("subMenu").onmouseover = function(breakTimeout) { // **Code A**
                a = 10000;
                // **Stop timeout.**  Now never execute Code B.
                document.getElementById("subMenu").onmouseout = function(endFunction) {
                    document.getElementById("subMenu").innerHTML = '<tr><td>Content is Dynamic!</td></tr>';
                    // **Exit function here immediately**
                }
            }
            if(a==500){
            //**Code B**:  Only execute if **Code A** never executed within time frame
                document.getElementById("subMenu").innerHTML = '<tr><td>Dynamic Content!</td></tr>';
            }
        }, a)
    }
}​

I hope the concept of my design is also evident. If my code and description is not clear enough, I’ll be glad to clarify further questions.

Thanks a lot and +1 to anybody who can get the answer!

  • 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-05T05:05:33+00:00Added an answer on June 5, 2026 at 5:05 am

    Your original premise was flawed. The body of the function passed to setTimeout() doesn’t execute until after the time has elapsed, so the code you wanted to stop the timeout wouldn’t be executed until it was too late. I’ve modified your code to use a standard clearTimeout() which should do what I think you want.

    var a = 500, head1 = document.getElementById('head1'), subMenu = document.getElementById('subMenu'), timeout;
    
    head1.onmouseover = function(displayMenu) {
        subMenu.innerHTML = '<tr><td>Item A</td><td>Item B</td><td>Item C</td></tr>';
        head1.onmouseout = function(getScroll) {
            subMenu.onmouseover = function(breakTimeout) {
                clearTimeout(timeout);
                subMenu.onmouseout = function(endFunction) {
                    subMenu.innerHTML = '<tr><td>Content is Dynamic!</td></tr>';
                };
            };
            timeout = setTimeout(function() {
                document.getElementById("subMenu").innerHTML = '<tr><td>Dynamic Content!</td></tr>';
            }, a);
        };
    };
    

    Working DEMO

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

Sidebar

Related Questions

I have a program that normally run till it terminates, but under some situations,
Normally it is said that multi threaded programs are non-deterministic, meaning that if it
I have a class that will normally run under Windows and uses the win32com
I have a .js file that normally gets executed by cscript.exe (i.e. is not
I have a desktop application that on first execution prompts for the connection details
We are implementing a fly out messaging system that will normally fly out while
From a script in Matlab, I need to run an external command. Normally this
Is there any way to enable execution-time variable expansion for cmd.exe (normally done by
Normally windows forms applications proceeds execution as the user gives the input(s). ex :
I have a class that I've created to allow asynchronous sequential execution of tasks,

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.