Visit Mozilla.org

DOM:event.relatedTarget

From MDC

« Gecko DOM Reference

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 mouseover event and the non-standard dragenter event this property indicates the EventTarget which the pointing device exited
  • For the mouseout event and the non-standard dragexit event this property indicates the EventTarget which the pointing device entered.

See also Comparison of Event Targets.

[edit] Syntax

target = event.relatedTarget
  • target is a reference to the secondary EventTarget for 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.

[edit] Specification

DOM Level 2 Events: MouseEvent.relatedTarget