Try the following:
function reveal_board() { $("div").each(function(index) { (function(that, i) { var t = setTimeout(function() { $(that).removeClass("invisible"); }, 500 * i); })(this, index); }); }
Itβs usually not good practice to pass a string to setTimeout()
, and I donβt think that you can pass any variables when using it this way.
I also wrapped it in a closure to ensure that that
always applies to the right element and is not replaced.
Although, like NiftyDude, you can go to the index and use it to display each item in turn.
Working example - http://jsfiddle.net/Cc5sG/
EDIT
It seems you do not need to close:
function reveal_board() { $("div").each(function(index) { var that = this; var t = setTimeout(function() { $(that).removeClass("invisible"); }, 500 * index); }); }
http://jsfiddle.net/Cc5sG/1/
source share