jQuery setTimeout delay for an element

Posted by Trouble on Pro Webmasters See other posts from Pro Webmasters or by Trouble
Published on 2012-10-01T19:37:40Z Indexed on 2012/10/01 21:52 UTC
Read the original article Hit count: 173

Filed under:

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.

© Pro Webmasters or respective owner

Related posts about jQuery