Mark Timothy
Mark Timothy

Reputation: 1814

JQuery while loop and setTime out function lead to stuck the browser

I'm trying to automate a slider by using following Jquery code

while(true){
    setTimeout(function(){
        $('.bx-next').click();
    }, 3000);
}

but this leads to crash the browser.. Any better way???

Upvotes: 1

Views: 115

Answers (1)

scrowler
scrowler

Reputation: 24406

If you want an endless loop every 3000 ms, use setInterval not setTimeout and get rid of the while(true):

setInterval(function() {
    $('.bx-next').click();
}, 3000);

Docs: http://www.w3schools.com/jsref/met_win_setinterval.asp

Upvotes: 3

Related Questions