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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:59:37+00:00 2026-05-27T21:59:37+00:00

I just find an interest thing, when you change an element’s src, it’ll have

  • 0

I just find an interest thing, when you change an element’s src, it’ll have several seconds delay and the line under it will execute before new picture rendered, so it’ll load latter picture’s size(width height) if you want to get the size immediately after change a picture’s src.

heres the evidence:


$("button").click(functon() { //set a button so you can handle the process.

var alert1 = $("#image").width(); //#image is an <img> element, don't set width and height.

var src = pictures.pop(); //pictures is an array which stored image base64 code.

$("#image").attr("src", src);

var alert2 = $("#image").width();

alert("alert1: " + alert1 + " alert2: " + alert2);

}

as the code shows, after it executed, the alert1 should show the width of the picture before change src, alert2 should show the width of picture after change src.

but what i actually see? both alert1 and alert2 all show the width of picure befor change src.

to enhance my opinion, there’s another exp:


$("button").click(functon() { //set a button so you can handle the process.

var alert1 = $("#image").width(); //#image is an <img> element, don't set width and height.

var src = pictures.pop(); //pictures is an array which stored image base64 code.

$("#image").attr("src", src);

alert("wait");

var alert2 = $("#image").width();

alert("alert1: " + alert1 + " alert2: " + alert2);

}

see? i add an alert box after change src so i can control the code to execute after change src, then what happened, the alert1 return the width of picture before change src and the alert2 return the width of picture after change src! so it’s proved that the process of src is done after the code after it executed.

What I want to know is why this happen, what happened when chrome change picture’s src?

ps: I just try this on chrome, if you are interested in this can do the same exp on other browdser.

  • 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-27T21:59:37+00:00Added an answer on May 27, 2026 at 9:59 pm

    This is probably because the image has not yet loaded. Why not put the code in the img’s onload event? This way it will not fire until the image has completely loaded.

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

Sidebar

Related Questions

I just find out about the power of date js, And its great!!! As
I'm trying to write (or just find an existing) PHP method that can take
we are looking for a way to find out (not modify, just find out)
I just wanna find out if there's a way I could minimize code clutter
Just curious to find out exactly what problems I'll cause myself if I include
I just want to find out how to run two WPF windows (one in
Is it just me who find the following code intrinsically backwards? I am using
I know this has been asked thousands of times but I just can't find
I am sticking my toe in the RESTful waters and I just can't find
I've searched their site. I just want to find the page number in the

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.