JavaScript: mouseenter event in JavaScript?

Navneet Saini picture Navneet Saini · May 23, 2013 · Viewed 9.8k times · Source

Is there a mouse enter event in javascript(only JavaScript, no jQuery to be used, please)?

When I do this, it gives no response.

window.onload = initAll;
function initAll(){
    if(window.addEventListener){
        document.getElementById('container').addEventListener( 'mouseenter', freeze , false);
    }
}

function freeze(){
    console.log("mouse entered")    
}

Could someone Please explain me the difference between 'mouseenter' and 'mouseover'? Is 'mouseover' an alternative for 'mouseenter'?

Help Appreciated!

Answer

gwin003 picture gwin003 · May 23, 2013

Don't bother with onmouseenter, as this page states its specific to IE.

...Both onmouseenter and onmouseover fire when the mouse enters the boundary of an element. However, onmouseenter doesn't fire again (does not bubble) if the mouse enters a child element within this first element.

Try this for onmouseover:

yourObject.onmouseover=function()
    {
        //SomeJavaScriptCode
    };

Check this page for some good info on javascript mouse events.