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

The Archive Base Latest Questions

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

For example, let’s say I use the .addClass() method. You can’t append a callback

  • 0

For example, let’s say I use the .addClass() method. You can’t append a callback to it (e.g. you can’t do $(‘…’).addClass(‘…’).load(‘…’) ).

In most cases, you can just call your functions back to back before using .load() and you’re fine.

But what if I have a super slow computer where using .addClass() takes 5 seconds? How do I execute another asynchronous function only after .addClass() has finished, or for that matter, after any JavaScript asynchronous function is finished?

EDIT: I was wrong, .addClass is not asynchronous.

So, then, just to be sure:

$('foo').addClass('');
/*this code here will not execute UNLESS the previous line is absolutely finished?*/
  • 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-22T01:55:59+00:00Added an answer on May 22, 2026 at 1:55 am

    addClass is not asynchronous, and there is no environment in which it will take any significant time to perform its job. jQuery’s various operations that are asynchronous (ajax, effects, that kind of thing) accept callbacks as part of their API.

    I think (without going back and re-reading the API) that if an API function doesn’t have a callback, you can assume the operation is synchronous.

    The converse is not true; jQuery has several API functions (each, for instance) that accept callbacks that aren’t asynchronous, it’s just that the callback is handy for other reasons.

    In any case, any asynchronous operation should be clearly identified as such in the documentation.

    Update: Addressing your updated question: Correct, the code after addClass will not execute until addClass is complete. Even if it took a second or two (which of course it doesn’t, but let’s pretend), addClass will plod through doing its thing, and return back to your code. The subsequent code won’t run until it does, and no other code can run while that’s happening (because JavaScript on web browsers is single-threaded unless you use web workers, and even then coordination between threads is explicit).

    There are some operations where you have to give the browser a moment to process what you’ve told it to do. I’m trying to think of a specific example, something around adding form fields in IE. Definitely not simple things. In those rare situations, you can ensure you’ve given the browser an opportunity to do its thing by explicitly yielding to the browser with a setTimeout:

    doSomethingTheBrowserHasToThinkAbout();
    setTimeout(function() {
        // Now you know the browser's had time to think about it
        doSomethingElse();
    }, 0); // <== Won't really be 0, most browsers clamp this to 5-10ms minimum
    

    But you don’t have to do that (and don’t want to do that) except for certain specific operations. I’m sorry I’m not immediately remembering an example, but we’re talking edge cases here.

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

Sidebar

Related Questions

how can I replace 2 strings in the same time? for example let's say
I'm having some trouble writing a query. For example: Let's say I have just
For Example: Let's say that I want to return a view that displays a
A simple example: Let's say I have one alias being sourced somewhere as: alias
Let's say for example I wanted to echo You are using Windows! or You
Let me use the following example to explain my question: public string ExampleFunction(string Variable)
What's the best way to thread work (methods) in c#? For example: Let's say
For example: Let's say I'm grabbing a list of names and saving it to
I'm struggling with the F# type signature notation. For example let's say you have
I have 1 or more items in an array, for this example let's say

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.