I am trying to do something that I thought was simple but I need some help.
inside a jquery function I want to set a timer and clear it from another function….
(function($){
var mnuTimer;
var mnuDown;
$('.nav-menu .parent').hover(function(){
clearTimeout(mnuTimer);//clear function
$(this).children('.children').slideDown();
$(this).css('background-color','#fff0c8');
},
function(){
function mnuDown(){//set function for timer experation
$(this).children('.children').slideUp('fast');
$(this).css('background-color','transparent');
}
mnuTimer = setTimeout("mnuDown()",1000)//timer
});
})(jQuery);
So the only part I can’t get working is the timer. the “mnuDown” function comes up undefined. I have tried a lot of different ways to make it work and nothing seem to be correct except declaring the function outside of the jquery “(function($){“. This will not work because the whole reason I’m using jquery is to apply the slideUp animation which is not available outside jquery. AHHH help, Thanks
Yes, not the declaration of the function is the problem but the [variable] referencing it: You have none. Instead,
setTimeout("mnuDown()",1000)will eval that code string in the global scope – nomnuDownto be found there. You need to pass the function reference tosetTimout():