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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:46:55+00:00 2026-05-30T18:46:55+00:00

I started learning jQuery today and I’m facing an issue, I was under the

  • 0

I started learning jQuery today and I’m facing an issue, I was under the impression that the order you write code in jQuery is the order it executes it, apparently I’m wrong. for example I’d like to tell it to put my text blue but then change it to red. I can’t get that to work because it seems to fight for the element (my guess is it runs at the sametime all functions), even if I put in a delay. Any ideas on this?

here’s my code: http://jsfiddle.net/jZUzP/

$(document).ready(function(){
    $(".post").css({"color":"#0000FF"})
              .delay(800)
              .css({"color":"##FF0000"});    
});
  • 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-30T18:46:56+00:00Added an answer on May 30, 2026 at 6:46 pm

    In a general sense jQuery code is executed in the order it appears, the same as for any other JavaScript code. However, functions that make use of setTimeout() or Ajax may execute something after a delay.

    In the case of the code from your question, you are using the .delay() method, which adds a delay only to jQuery animation effects, and the .css() method does not participate in animation. So as indicated in Felix’s comment, the two css changes happen immediately after each other, too fast to see the first colour.

    More specifically, your first .css() call happens, then the .delay() call happens but what it does is add a delay to the animation queue and then return immediately, and then your second .css() call happens. If you then queued up other animation effects they would happen after the delay. Browsers run JavaScript in a single thread, so you won’t ever have two blocks of code running at the same time – and note that that single thread is also the one the browser uses to render (which is why long-running loops make the browser unresponsive).

    So, you might naturally ask, isn’t there a way to change css settings in a way that does participate in jQuery’s animation process? Well yes, you can use the .animate() method – except that it doesn’t work on colours. At least, not by default. But if you include the jQuery UI extension to jQuery then you can use .animate() to change colours as follows:

    $(document).ready(function() {
        $(".post").animate({
            "color": "#0000FF"
        }, 0).delay(800).animate({
            "color": "##FF0000"
        }, 0);
    });
    

    Demo: http://jsfiddle.net/jZUzP/1/

    Note that the above called .animate() with a duration of 0 so that the colour change would be instantaneous.

    Further reading:

    • jQuery standard .animate() doco
    • jQuery UI .animate() doco

    If you don’t want to include jQuery UI as well as jQuery just for something simple like this you can of course use the (non-jQuery, standard JS) setTimeout() function to queue up your second css change:

    $(document).ready(function(){
        var $post = $(".post").css({"color":"#0000FF"});
        setTimeout(function() {
            $post.css({"color":"##FF0000"});
        }, 800);
    });
    

    (jQuery animation effects use setTimeout() internally.)

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

Sidebar

Related Questions

Question 1 I've just started learning jQuery and one thing that puzzles me is
Started learning javascript yesterday at CodeAcademy and decided I could actually write code. Just
I'm just getting started with learning jQuery, and I'm having a small CSS issue.
I've just started learning Jquery but the examples aren't helping me much... Now whats
I have just started learning Jquery and am new to writing javascript (I am
Where is a good place to get started learning how to use jQuery? It
I started learning jQuery just yesterday, and I like it very much. And now
I've just started learning jQuery/javascript, so this might seem like a really basic question,
I've started learning the jquery mobile framework so I can bring my existing website
I have started learning MVC2. I developed a simple customer search screen with Jquery

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.