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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:17:09+00:00 2026-05-30T20:17:09+00:00

This is the code : // link 1 handler. This must finish in any

  • 0

This is the code :

// link 1 handler. This must finish in any case before link2 starts
$('#link1').click(function () {
    console.log("First Handler");
    setTimeout(function() {
        console.log("Thread???");
    }, 2000);   
});

// link 2 handler. It starts only when block code of link1's handler finish
$('#link2').click(function () {
    console.log("Second Handler");    
});    

$('#link1').click();
$('#link2').click();

clicking, in sequence, on link1 and link2, means (for what I understand) that block code of link2’s handler can’t start before link1’s handler finish (because JS is single thread, and system events is synchronous).

Well, so, why about console.log("Thread???"); that will be printed after 2sec? I see it such as a thread. Also, the behaviour it’s the same…

  • 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-30T20:17:10+00:00Added an answer on May 30, 2026 at 8:17 pm

    When the handler is fired for link1, it runs the entire function, including the setTimeout function that merely registers the function that runs your console.log("Thread???") statement. This happens very quickly. Think of this like you would cocking a firearm. You haven’t fired, you’ve just prepared to fire and are performing a 2 second countdown.

    In other words, the setTimeout function does not block the execution of any other functions and (emphasis added) does not force link2 to wait. As far as link1’s handler is concerned, it did it’s job, and the JavaScript engine proceeds to execute link2’s handler, which also finishes well before your 2000ms event fires.

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

Sidebar

Related Questions

Check out this code : <a href=# id=link>Link</a> <span>Moving</span> $('#link').click(function () { console.log(Enter); $('#link').animate({
this code: $(document).ready(function() { $('body').click(function(evt) { if(evt.target.nodeName === 'A' && $(evt.target).hasClass('cross-link')) { $('a[href=#2]').trigger('click'); }
I have this code in the end of link button click: Response.ContentType = application/zip;
i have this code: $('.access a').toggle(function() { $('link').attr('href', 'styles/accessstyles.css'); $('body').css('font-size', '16px'); }, function() {
Following code for passing an object to event handler is not working: $('a.another').live('click', function(e,
I try to use this code for toggling text on the link: var showText=<span>Open</span>
I got this code in order to build an url for the link using
I want to add this code: <link rel=stylesheet type=text/css href=css/global.css /> <!--[if lt IE
When i use this code <!--[if IE 6]> <link rel=stylesheet href=ie6.css type=text/css /> <![endif]-->
I have borrowed code from this link PHP regex templating - find all occurrences

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.