I want to trigger an event when the mouse leaves two elements. I found the following jsfiddle which is exactly what I’m looking for:
It uses this code:
var count = 0;
$('#d1, #d2').mouseenter(function(){
count++;
$('#d3').show();
}).mouseleave(function(){
count--;
if (count == 0) {
$('#d3').hide();
$('#d3').css('background-color', 'orange');
}
});
However, the event still gets triggered, as you can see by the div changing its background color.
I want the event only to be triggered when the mouse really leaves both elements.
How about:
jsFiddle
The small timeout is to make sure the mouse actually left both elements, rather than left one and entered another.