I need to track mouseenter / mouseleave events for all elements on the page.
Intuitively written code for it was:
$(window).on('mouseenter mouseleave', function(e) {
console.log(e.target, e.type);
// ...
});
But it fires mouseleave events every time mouseenter happens on child element, thus nullifying all benefits of mouseenter/mouseleave, i.e. it works like mouseover/mouseout.
Is there a way to handle this without attaching handlers directly to all elements?
And does this look like a jQuery bug? Because from what I know and from jQuery docs I've read it looks like the above code should work fine.
JSBin to play with: http://jsbin.com/axuluc/2/
Edit: this works as expected: http://jsbin.com/axuluc/9/