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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:13:10+00:00 2026-06-12T00:13:10+00:00

i am still new to all the Javascript stuffs and i have to be

  • 0

i am still new to all the Javascript stuffs and i have to be honest that i have not yet experimented anything concerning my question.

I would like to know if there is a way or a plugin with jQuery to preloaded multiples images and call a function when the images are loaded?

  • 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-12T00:13:11+00:00Added an answer on June 12, 2026 at 12:13 am

    You can use the load event for images, but they have a number of cross browser issues (it depends on what platforms you’re targeting).

    var allImgs = $("#container img").filter(function() { return ! this.complete; });
    var allImgsLength = allImgs.length;
    
    allImgs.on("load", function() {
        if (--allImgsLength) {
            // Images have loaded.
        }
    });
    

    If you don’t mind including a plugin, there is waitForImages, (disclaimer: written by me) which handles this relatively nicely. 🙂

    You’d use it like…

    $("#container").waitForImages(function() {
        // Images have loaded.
    });
    

    If you don’t want to use jQuery at all, you can adapt the first example. If you’re only targeting modern browsers…

    var allImgs = [].filter.call(document.querySelectorAll("#container img"), 
                                 function(img) {
                                    return ! img.complete;
                                 });
    var allImgsLength = allImgs.length;
    
    [].forEach.call(allImgs, function(img) {
        img.addEventListener(function() {
            if (--allImgsLength) {
                // Images have loaded.
            }
        });
    });
    

    If you had to support old browsers…

    var allImgs = document.getElementById("container").getElementsByTagName("img");
    var allImgsLength = allImgs.length;
    var i;
    var eventCallback = function() {
                            if (--allImgsLength) {
                                 // Images have loaded.
                            }
                        };
    
    for (i = 0; i < allImgsLength; i++) {
        if (allImgs[i].complete) {
            allImgsLength--;
        }
    
        if (allImgs[i].addEventListener) {
            allImgs[i].addEventListener("load", eventCallback);
        } elseif (allImgs[i].attachEvent) {
            allImgs[i].attachEvent("onload", eventCallback);
        } else {
            allImgs[i].onload = eventCallback;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

still new to XML parsing with the iphone so i have a few questions.
I'm still new to Core Data, so forgive the question. I'm building an app
I am still new to LINQ, and I have wrestled with a query for
I'm fairly new to facebook development, but have experience with PHP and JavaScript. I've
I have a userscript (read: my Javascript on someone else's site) that allows users
Fought with a bunch of examples and, being still new to jQuery/Javascript, cannot get
I'm not new to JavaScript, but I never could understand a certain thing about
I am still new to javascript, and I am trying to get a function
I'm making a simple affiliate ad rotation JavaScript. I'm still new to JavaScript and
I've finally figured out how to make all my millions of tabs (not that

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.