Wednesday, July 21, 2010

What element mouse comes from or goes to

Sometimes we want to know where the mouse comes from or goes to in case of mouseover / mouseout event. Assume, we have assigned to any HTML element a mouseout listener mouseOut. We can easy acquire the source (from element) and target (to element) by fired event.
function mouseOut(evt)
{
    evt = (evt) ? evt : ((window.event) ? window.event : "");
    var fromElement = (evt.target) ? evt.target : evt.srcElement;
    var toElement = (evt.relatedTarget) ? evt.relatedTarget : evt.toElement;
    
    // do something with fromElement / toElement
}
Easy. Is not?

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.