FocusEvent relatedTarget Property

Example

Get the related element of the element that triggered an onfocus event:

function getRelatedElement(event) {
  alert(event.relatedTarget.tagName);
}
Try it Yourself »

Description

The relatedTarget property returns the element related to the element that triggered the focus/blur event.

  • For onfocus and onfocusin events, the related element is the element that LOST focus.
  • For onblur and onfocusout events, the related element is the element that GOT focus.

This property is read-only.


Syntax

event.relatedTarget

Technical Details

Return Value: A reference to the related element, or null if there is no related element
DOM Version: DOM Level 3 Events

Browser Support

event.relatedTarget is a DOM Level 3 (2004) feature.

It is fully supported in all modern browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 11


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.