Mittwoch, 21. Dezember 2011

setTimeout() && setInterval() scope problem solver

This is so handy from time to time:
setInterval(
    function () {
        var myVar = document.getElementById("givenID");
        setTimeout(
            function() {
                // myVar is available because the inner closure 
                // gets the outer closures scope
                myVar.innerHTML = "Junk";
        },2000);
    }, 10000);

Source: Stackoverflow

Keine Kommentare:

Kommentar veröffentlichen