56

I'm trying to have a simple html table, that highlights a row as a user mouses over it. Unfortunately the css hover item doesn't work for IE. That leaves me to simulate it in Javascript. I can use either onmouseenter or onmouseover.

What is the difference between them, and which one should I use?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
C. Ross
  • 31,137
  • 42
  • 147
  • 238

3 Answers3

80

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.

asliwinski
  • 1,662
  • 3
  • 21
  • 38
Chetan S
  • 23,637
  • 2
  • 63
  • 78
  • 10
    Update: Firefox started supporting `onmouseenter` in version 10 (January 2012) and Chrome started supported it in version 30 (October 2013) ([source](https://developer.mozilla.org/en-US/docs/Web/Events/mouseenter)). I couldn't find info for Safari other than [this webkit bug](https://bugs.webkit.org/show_bug.cgi?id=18930), where the fix was committed in April 2013. So `onmouseenter` should work for most users of major browsers now. – ecraig12345 Jan 14 '15 at 06:11
8

Unlike the onmouseover event, the onmouseenter event does not bubble. In other words, the onmouseenter event does not fire when the user moves the mouse pointer over elements contained by the object, whereas onmouseover does fire.

I always use onmouseover. I use onmouseover in the same purpose (highlights a row).

Arkadiusz Kondas
  • 454
  • 8
  • 13
1

You might spare yourself some coding by just adding :hover support for all elements in IE too:
try csshover.htc

djn
  • 3,950
  • 22
  • 21
  • css behaviors are waaaay slow. They run everytime a thread stops executing. Try adding some logging into the js from the htc to see this. If you're just tring to create a hover effect. We use :hover which works for everybody except IE6. Death to IE6. I think this is acceptable because hover effects are just a nice to have. – Ruan Mendes Mar 04 '10 at 19:21