In a library I am using I have the task of moving an element to the front of the dom when it is hovered over. (I make it bigger so I need to see it, then shrink it back when
The problem is that IE handles mouseover
differently, because it behaves like mouseenter
and mousemove
combined on an element. In other browsers it's just mouseenter
.
So even after your mouse has entered the target element and you've changed it's look and reappended it to it's parent mouseover
will still fire for every movement of the mouse, the element gets reappended again, which prevents other event handlers from being called.
The solution is to emulate the correct mouseover
behavior so that actions in onmouseover
are executed only once.
$("li").mouseover( function() {
// make sure these actions are executed only once
if ( this.style.borderColor != "red" ) {
this.style.borderColor = "red";
this.parentNode.appendChild(this);
}
});
Examples
mouseover
difference between browsers (bonus: native javascript)