DOM:event.relatedTarget
From MDC
Contents |
[edit] Summary
Identifies a secondary target for the event. Only MouseEvents have this property, and its value makes sense only for certain MouseEvents:
- For the
mouseoverevent and the non-standarddragenterevent this property indicates theEventTargetwhich the pointing device exited - For the
mouseoutevent and the non-standarddragexitevent this property indicates theEventTargetwhich the pointing device entered.
See also Comparison of Event Targets.
[edit] Syntax
target = event.relatedTarget
-
targetis a reference to the secondaryEventTargetfor this event. See Summary for details.
[edit] Example
var rel = event.relatedTarget;
// dump("LEAVING " + (rel ? rel.localName : "null") + "\n");
// relatedTarget is null when the titletip is first shown:
// a mouseout event fires because the mouse is exiting
// the main window and entering the titletip "window".
// relatedTarget is also null when the mouse exits the main
// window completely, so count how many times relatedTarget
// was null after titletip is first shown and hide popup
// the 2nd time
if (!rel) {
if (++this._mouseOutCount > 1)
this.hidePopup();
return;
}
// find out if the node we are entering is one of our
// anonymous children
while (rel) {
if (rel == this)
break;
rel = rel.parentNode;
}
// if the entered node is not a descendant of ours, hide
// the tooltip
if (rel != this && this._isMouseOver) {
this.hidePopup();
}
[edit] Notes
The relatedTarget property is used to find the other element, if any, involved in an event. Events like mouseover are oriented around a certain target, but also involve a secondary target, such as the target that is exited as the mouseover event fires for the primary target.