I currently have an element and when I 'mouseenter' that element there should be a delay before the code in 'mouseenter' is executed.
I've achieved that with the following code:
$('.element').mouseenter( function() {
setTimeout(function() {
$('#output').append("Mouse enter.</br>");
},5000);
});
So here, in my output 'Mouse enter.' will be placed but only after 5 seconds. Now, when my mouse cursor is moved out of the element within the 5 seconds, the code should not be executed.
I've tried with the following javascript function but it isn't working:
$('.element').mouseout( function(e) {
e.stopPropagation();
});
I've created a fiddle demo to show it:
Basiclly the question is:
"How can I cancel my code which is in my timeout function" when my mouse moves out of the area on which the mouseenter is set?"