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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:18:34+00:00 2026-06-05T09:18:34+00:00

After I make an ajax request by doing something simple like $(element).load(url, callback); there

  • 0

After I make an ajax request by doing something simple like $(element).load(url, callback); there will be new content on the page that includes images and such.

Is there a way to do something similar to $(window).load(callback) after the new content has finished loading?

$(window).load(); works nicely when the page is fresh so that you can show a load animation until all content is loaded, but something simple like this seems to be missing for when content is loaded after $(window).load() has already been triggered.

EDIT 6/6/12 11:55pm: I think everyone is misunderstanding my question. Let me explain a little better:

When you first load a page, you can take advantage of these two events with jQuery: $(document).ready(); and $(window).load();. The first one fires when the DOM is ready and the second one fires when content is done being loaded (images, etc). After updating the page using jQuery’s .load() method, I am fully aware that I can pass a callback to be executed after the Ajax is completed.

That is not what I want. I want to execute a function after the new content is finished loading, similar to when $(window).load(); fires after a page’s initial content has finished loading.

Does that make sense? How can we create an event similar to $(window).load(); for doing stuff after Ajax’ed content is done loading (not just after the HTML has been inserted)?

  • 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-05T09:18:37+00:00Added an answer on June 5, 2026 at 9:18 am

    According to jQuery:

    The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

    So, after the DOM has been updated (with Ajax’ed content for example), I am setting a listener for the ‘load’ events on all newly inserted images:

    function when_images_loaded($img_container, callback) { // do callback when images in $img_container (jQuery object) are loaded. Only works when ALL images in $img_container are newly inserted images and this function is called immediately after images are inserted into the target.
        var _imgs = $img_container.find('img'),
            img_length = _imgs.length,
            img_load_cntr = 0;
    
        if (img_length) { //if the $img_container contains new images.
            _imgs.on('load', function() { //then we avoid the callback until images are loaded
                img_load_cntr++;
                if (img_load_cntr == img_length) {
                    callback();
                }
            });
        }
        else { //otherwise just do the main callback action if there's no images in $img_container.
            callback();
        }
    }
    

    This is nice for allowing content to remain hidden until images are ready. If you have background images that will be showing as background images, this won’t work. A workaround would be to load all the images that you are using in your CSS styles into a container that will remain hidden so that the above function will allow you to load the images. Once all the images are loaded, you can remove the element that contains your CSS-only images and that way the browser will render backgrounds (etc) instantaneously when you unhide your content.

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

Sidebar

Related Questions

I make an ajax request, and the JSON response, after parsing, gives me the
I'm building a web-based chat app which will need to make an AJAX request
My lightview modal keeps closing after an Ajax request. Meaning when I make an
I want to write a javascript function, that will make an ajax request to
I call sortable.stop() to make an ajax call to store some data after drag
Event-delegation must be used to make events work after inserting DOM elements (i.e Ajax
When I bring my server down and make an ajax request to it, firebug
I get a table from the server using ajax request. After I insert the
After a page loads, I'm making an AJAX request to pull down an HTML
I'm creating a website where I'm doing ajax requests to load some dynamic content

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.