function foo() { alert('foo!'); } var timer; $(document).ready(function() { $('#link').mouseover(function() { timer = setTimeout(foo, 2000); }).mouseout(function() { clearTimeout(timer); }); });