I have a deferred function that binds a mouseenter event:
$(window).load(function(e) {
var $container = $('.container');
$container.mouseenter(function(e) {
//do something
});
...
});
The problem is the mouse might already be over the element when the load event fires, hence before the mouseenter event was bound.
I can get around this by putting some code at the end of the page load handler to do a one-time check if the mouse is inside the element and trigger the mouseenter event manually:
// check if the mouse is inside $container
if(mouse is inside $container)
$container.mouseenter();
How can I check if the mouse is over the element in the load event?
I tried $container.is(':hover') but it doesn’t work.
I went with the css hover solution in Detect mouse hover on page load with jQuery because it doesn’t require the mousemove event.