How about using closure like this?

function addHoverHide(linkClass, layerId) {
  var t;
  $("." + linkClass).hover(function() {
    clearTimeout(t)
    $("#" + layerId).show();
  }, function() {
    t = setTimeout(function() {$("#" + layerId).hide()}, 2000);
  });
}
$(document).ready(function () {
  addHoverHide("some_link", "this_layer");
  addHoverHide("some_other_link", "this_other_layer");
});

Untested but the idea should work.  Good luck.

David

On Jan 23, 6:42 pm, gr00vy0ne <[EMAIL PROTECTED]> wrote:
> 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?

Reply via email to