so I am trying to do some dynamic hover manipulations, which require using this in jquery. For some reason that I cannot figure out, the javascript setTimeout function does not seem to support it.
I understand that the setTimeout function is not Jquery, but if placed inside a Jquery function, shouldn't it be able to respond to the relevant this?
Here is some sample code:
var go = false;
var t;
$('.box').mouseenter(function(){
t = setTimeout(function(){
go = true;
alert($('span',this).text());
},1000);
});
$('.box').mouseleave(function(){
clearTimeout(t);
if(go){
alert($('span',this).text());
}
});
when hovering for 1 second it will alert a blank, yet on mouseleave it will alert the correct text even though both alerts are inside a Jquery function with the same selector.
Why does this happen and how can I fix it?