I want to display a div when you hover over another DOM element, but I want to cancel this action if you move the mouse before the div is shown. So far this is what I have
HTML
<div id="msg">
<a href="#" id="33"> HERE </a>
</div>
JS
var timer;
$("body").on('mouseenter', '#msg a',function(){
var userHover = $(this).attr("id");
timer = setTimeout(function () {
alert(userHover);
}, 1000);
}).on('mouseleave', '#msg a', function(){
});
Any help is appreciated.
You are looking for
clearTimeout():However, in case you have more than one element matching
#msg aI’d highly recommend you to store thetimervalue in the element-specific data.