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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:55:51+00:00 2026-05-25T14:55:51+00:00

I was using something like this: $(document).ready(function() { $(‘#my-img’).load(function() { // do something });

  • 0

I was using something like this:

$(document).ready(function() {
  $('#my-img').load(function() {
    // do something
  });
});

But sometimes it fails to execute the second callback (without throwing any errors, so there’s nothing to do there), and I’m thinking that maybe the image is being loaded before the document is ready.

If I don’t use the $(document).ready() part, it works fine, so I think I’m gonna leave it that way for now. But someone told me that it was a good practice to always do this kind of thing as a callback on document ready, because the document might not be ready. Is that right?

Any thoughts?

  • 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-25T14:55:52+00:00Added an answer on May 25, 2026 at 2:55 pm

    Taken from the documentation on load()

    Caveats of the load event when used with images

    A common challenge developers attempt to solve using the .load()
    shortcut is to execute a function when an image (or collection of
    images) have completely loaded. There are several known caveats with
    this that should be noted. These are:

    It doesn’t work consistently nor reliably cross-browser

    It doesn’t fire correctly in WebKit if the image src is set to the same src as before

    It doesn’t correctly bubble up the DOM tree

    ****Can cease to fire for images that already live in the browser’s cache****

    Especially the latter is a common problem.

    You might try the imagesLoaded plugin, but I’ve had better luck with the following approach:

    var element = $('#my-img');
    $("<img/>").load(function () { //create in memory image, and bind the load event
        //do something
        //var imageHeight = this.height;
    }).attr("src", element.attr("src"));
    //set the src of the in memory copy after binding the load event, to avoid WebKit issues
    

    It’s dirty, but if you really need to perform some action after the image has loaded this has been the only reliable approach I’ve been able to get to work.

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

Sidebar

Related Questions

I have some jQuery code something like this: $(document).ready(function() { $(img.off).click(function() { alert('on'); $(this).attr('class',
Basically I want to do something like this: $(document).ready(function() { if ($(body).attr(class) === HomePage)
I'm using nokogiri with an xml document that looks something like this: <songs> <song>
My application has something like the following structure window.object1; window.object2; $(document).ready(function() { window.object1 =
I'm using this function: $(document).ready(function() { $('.gdthumbtext') .contents() .filter( function(){ return this.nodeType == 3;
Using something like this: try: # Something... except Exception as excep: logger = logging.getLogger(component)
I'm using something like this on my server: TcpServerChannel channel = new TcpServerChannel(settings.RemotingPort); ChannelServices.RegisterChannel(channel,
Hoping that using something like this demo it is possible to drag items within
Freemarker has the ability to do text escaping using something like this: <#escape x
So, I'm trying to consume a webservice using something like this: $client = new

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.