Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

FocusEvent.relatedTarget — the other focus-transition target

FocusEvent.relatedTarget identifies the other object involved in a focus transition: the previous target when gaining focus or the next target when losing it. The property is read-only and may be null.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

event.relatedTarget
new FocusEvent(type, { relatedTarget: otherTarget })

FocusEvent represents the focus, blur, focusin, and focusout events. It inherits from UIEvent and indirectly from Event. Its FocusEvent.relatedTarget property describes the other target in a focus transition, not the target identified by event.target.

For focus and focusin, event.target identifies the object receiving focus, while event.relatedTarget identifies the object losing focus. For blur and focusout, the roles are reversed: event.target loses focus, and event.relatedTarget receives it.

relatedTarget is read-only and returns an EventTarget or null. The other target may be unavailable or concealed for security reasons, such as when tabbing into or out of a page. Check for null before using the value; do not assume every EventTarget is a DOM element either.

The new FocusEvent(type, options) constructor lets you set relatedTarget; its default is null. The example checks this option without depending on user interaction. FocusEvent is a browser Web API, not a feature of a particular ECMAScript edition. MDN marks the interface and property as widely available since July 2015; using Node 24 in a repository does not establish support for this API.

Examples

(() => {
  const previous = document.createElement("button");
  previous.id = "previous";

  const event = new FocusEvent("focus", {
    relatedTarget: previous
  });

  console.log(event.type);
  console.log(event.relatedTarget === previous);
  console.log(new FocusEvent("blur").relatedTarget === null);
})();

Result

focus
true
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources