This is more of a general javascript question but when using setTimeout and clearTimeout, does the "timer" variable have to exist outside the function globally?
For instance, I understand the following: var t; $(".some_link").hover(function() { clearTimeout(t) $("#this_layer").show(); }, function() { t = setTimeout(function() {$("#this_layer").hide()}, 2000); } Is there a way to create the timer within the jquery hover so that it's self-contained? Ideally, I'd like the timer to be dynamically created as necessary so if I add other hovers then I don't need to keep adding new variables to store the timer. Would I have to create an array that stores each unique timer? Is that the way to go?