Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeout doesn't seem to work in Chrome

This setTimeout works perfectly in Firefox, but in Chrome nothing in function timeoutTrigger ever happens, including the alert. Any ideas?

var $this = $('.active-more');

function timeoutTrigger() {
    $this.closest(".container").nextAll(".container:first").find(".description:first").removeClass('hide');
    $this.closest(".container").nextAll(".container:first").find(".back:first").find("img.portfolio").remove();
    alert("is this thing on?");
}

setTimeout(function(){timeoutTrigger()},400)
like image 581
maskedjellybean Avatar asked Jan 04 '13 03:01

maskedjellybean


People also ask

Why is my JavaScript code not working in Chrome?

Google ChromeIn the "Settings" section click on the "Show advanced settings..." Under the the "Privacy" click on the "Content settings...". When the dialog window opens, look for the "JavaScript" section and select "Allow all sites to run JavaScript (recommended)". Click on the "OK" button to close it.

Is setTimeout blocking?

Explanation: setTimeout() is non-blocking which means it will run when the statements outside of it have executed and then after one second it will execute. All other statements that are not part of setTimeout() are blocking which means no other statement will execute before the current statement finishes.

How do I avoid setTimeout?

You can also prevent the setTimeout() method from executing the function by using the clearTimeout() method. If you have multiple setTimeout() methods, then you need to save the IDs returned by each method call and then call clearTimeout() method as many times as needed to clear them all.


1 Answers

Switch your setTimeout statement to the following: setTimeout(timeoutTrigger,400); The one you wrote is for when the function you're calling has a parameter. Also, you're missing a semicolon.

like image 189
Shrey Gupta Avatar answered Sep 19 '22 20:09

Shrey Gupta