JavaScript: mouseenter event in JavaScript?

10,271

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.

Share:
10,271
Navneet Saini
Author by

Navneet Saini

Programming is not my field but it still takes my interest. I am mostly into web Programming(HTML, Javascript , CSS , PHP) stuff. I also have some knowledge about C and Java. Though, still a newbie in all these things. Looking forward to learn more and more here.

Updated on June 26, 2022

Comments

  • Navneet Saini
    Navneet Saini about 2 years

    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!

  • Navneet Saini
    Navneet Saini about 11 years
    So, is there no way to use 'mouseenter' with other browsers?
  • gwin003
    gwin003 about 11 years
    Apparently not according to that post. I normally use onmouseover anyways. You can use onmouseenter if you are using jQuery though, according to the first answer in my first link. api.jquery.com/mouseenter/…
  • Navneet Saini
    Navneet Saini about 11 years
    But mouseover keeps on firing again and again? how to prevent that?
  • Rachel Gallen
    Rachel Gallen about 11 years
    you could script a handler for that
  • Rob Johnstone
    Rob Johnstone about 11 years
    If you read what it says at the link you've posted, you'll see that mouseenter has nothing to do with clicks
  • Navneet Saini
    Navneet Saini about 11 years
    @RachelGallen I am not sure what you are talking about.. Can you please give me some lesson/tutorial link?
  • Rachel Gallen
    Rachel Gallen about 11 years
    basically you code a onmouseout at the same time...to negate the onmouseover
  • Navneet Saini
    Navneet Saini about 11 years
    @RachelGallen Thanks.. It helped
  • Navneet Saini
    Navneet Saini about 11 years
  • ChrisV
    ChrisV over 7 years
    That page says "Firefox started supporting onmouseenter in version 10 (January 2012) and Chrome started supported it in version 30 (October 2013)"