jQuery - load multiple files and then trigger an event

Viewed 3701

I'm trying to write code where if File A, B and C are loaded, an animation occurs. Right now I'm using the following code, but I was wondering if there isn't a simpler version to do this:

$(document).ready(function(){
    $("#file_A").load(function(){
        $("#file_B").load(function(){
            $("#file_C").load(function(){
            <!-- my animation script -->
            });
        });
    });    
});

This code though, doesn't really work for all situations. I would like something along the lines:

$(document).ready(function(){
    $("#file_A, #file_B, #file_C").load(function(){
    <!-- my animation script -->
    });    
});

Where basically I list all of the files I want to wait for to load and once that finishes, I start my animation script.

Thank you very much in advanced for any help!

3 Answers
Related