Skip to content Skip to sidebar Skip to footer

HTML5 + Jscript With JQuery, SetInterval Problem

Please can someone tell me why this isn't working before I defenestrate everything on my desk. I have the following html document:

Solution 1:

Change

    setInterval("render();", 1000);

To

    setInterval(render, 1000);

When you pass a string to setInterval(), the code inside is executed outside of the current scope. It's much more appropriate to just pass the function anyway. Functions can be passed around just like any other variable if you leave the parenthesis off.


Solution 2:

I'm not sure why using just "render()" doesn't work but using this code will fix the problem.

function startRendering() {
    setInterval(function(){
        render()
    }, 1000);
}

Post a Comment for "HTML5 + Jscript With JQuery, SetInterval Problem"