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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:15:56+00:00 2026-06-15T22:15:56+00:00

I am changing a image via jQuery, but the image takes a few seconds

  • 0

I am changing a image via jQuery, but the image takes a few seconds to load and hence appears like the click did nothing, so I needed to input a temporary “loading” image to show the user that the image is loading.

However as I have experienced in the past JS doesn’t really fire things as things happen, it waits until the full function is done before things happen; I recall coming up with a solution in the past but I just can’t remember what it was.

I have this which does each task, but the user never sees the loading image because it is replaced by the new image before the user even sees anything.

function changeMainImage(image) {

    // Set temporary loading image
    jQuery('#main_image').attr('src', 'images/loading.jpeg');    

    // Set big image
    var big_image = image + '-big.png'

    // Update main image url
    jQuery('#main_image').attr('src', big_image);

}

I have tried putting the below into a separate function:

// Set temporary loading image
jQuery('#main_image').attr('src', 'images/loading.jpeg');

..and calling it before the other function like so..

onclick="setLoadingIMage(); changeMainImage('images/ai');"

but that didn’t change anything.

Could anyone tell me what I need to do to achieve the effect I want?

  • 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-15T22:15:57+00:00Added an answer on June 15, 2026 at 10:15 pm

    This will display the loading.jpeg until the image has been loaded.

    function changeMainImage(image) {
    
        jQuery('#main_image').attr('src', 'images/loading.jpeg');
    
        var img = new Image();
        img.src = image + "-big.png";
    
        img.onload = function( ) {
              jQuery('#main_image').attr('src', img.src );
        }
    }
    

    If the image is held in cache then img.onload will fire immediately.

    Demo here

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

Sidebar

Related Questions

I am using jquery for changing image path but its not working for asp.net
I am changing the UIButton image on button click but it gets postion changes
It works in Firefox, but not in Chrome: changing the css property 'background-image' via
Possible Duplicate: Changing only y pos of background image via Jquery I want to
I would like to change the Windows 8 Lock Screen background image via c#
I know how to do it via using an image, but it needs to
i'm changing image of UIImageview by [self setImage: newImage]; Looks like every time I
I am taking an image, loading it via the screen context, and changing it
I've an img element with dynamically changing image. I always want to show this
I have this code for changing the image of a button: - (void)mouseEntered:(NSEvent *)event

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.