This will add a class mouse_over
when mouse enters either of the elements. It will then check that there are no mouse_over
elements when a mouseleave
is detected. The setTimeout is required to allow the mouseenter to fire before the mouseleave and may require additional tweaking to eliminate race conditions
$('.myDiv, .myDiv1').mouseenter(function () {
$(this).addClass('mouse_over')
})
$('.myDiv, .myDiv1').mouseleave(function () {
$this = $(this)
timeoutId = setTimeout(function () {
$this.removeClass('mouse_over')
if ($('.mouse_over').length == 0) {
console.log('not_in_either');
}
}, 1);
});