0

Is there an easier way to wait for an element to load ( by independant script/mootools/other ). For example:

I am waiting for a google map to load, but I don't want to use its API for checks. So I made two functions:

function checkIfexist() {
    if(jQuery('#container').length)
        return 0;
    else
        reload(1);
}

function reload(mode) {
    setTimeout(function(){
        do stuff
            .
            .
            .
        if(mode==1)
            checkIfexist();
    }, 400);
}

I am starting it with reload(1); Is there an easier way to use setTimeout in such a way? I don't want to use delay, wait or whatever.

2
  • Why wouldn't you use the Google Map API to check for map loaded completion? Commented Oct 1, 2012 at 22:50
  • Because this is not only for Google Map API, it is for all kind of AJAX requests, also done by otside site scripts. Best way is to use setTimeout and check after some time if it is loaded or not. Sometimes jQuery function doesn't give good results against foreign APIs for DOM. Commented Oct 2, 2012 at 0:27

1 Answer 1

1

.ajaxStop() fires when all concurrent ajax requests have finished, so you can just use it directly, for example:

$(function(){
    $(document).ajaxStop(function() {
        // all ajax is done
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you :) this works for jQuery though. What if we used javascript/mootools to inject elements after page load?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.