reset setTimeout

I am using this javascript code:

function delayhidemenu() {
     setTimeout("hideall()",5000)
}

This code will hide some html code after 5 seconds.
It works fine.

But is it possible to reset/disable the settimeout after it has been set. I use the code when I move the mouse from a link -> like this: onmouseout="delayhidemenu()".

However when I go over the link again in the 5 seconds the html text will be still hidden after the 5 seconds!
That is not what I want it to be!

Can this be done?
draco51Asked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
like this:


var myTimeoutID;

function delayhidemenu() {
    if (myTimeoutID)
       clearTimeout(myTimeoutID);
    myTimeoutID = setTimeout("hideall()",5000);
}
0
 
knightEknightCommented:
set your timeout like this:


   var myTimoutID = setTimeout("hideall()",5000);



then clear it like this:

   clearTimeout(myTimoutID);

0
 
knightEknightCommented:
... just make sure that the variable myTimeoutID is global in scope (i.e., not local to the function that calls setTimeout).
0
All Courses

From novice to tech pro — start learning today.