HTML DOM FocusEvent relatedTarget Property

The DOM FocusEvent relatedTarget Property is used to return the name of the Element that is related to that element that triggered the focus/blur event. It is read only Property. 

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

Syntax: 

event.relatedTarget

Return Value: It returns a reference to the related element or it returns a null if there are no related elements.

Example: In this example, we will see the use of DOM FocusEvent relatedTarget Property.

HTML




<!DOCTYPE html>
<html>
 
<body style="text-align:center;">
    <h1>w3wiki </h1>
    <h2>
        FocusEvent relatedTarget Property
    </h2>
    <textarea rows="4" cols="50">
        w3wiki.It is a
        computer science portal for Beginner.
    </textarea>
    <br>
    <br> Input field:
    <input type="text" onfocus="RelatedElement(event)">
    <p>
        <b>
            First click on Textarea element
            and then click the Textarea Element
        </b>
    </p>
    <script>
        function RelatedElement(event) {
            alert(
                "The related element that lost focus was: "
                + event.relatedTarget.tagName);
        }
    </script>
 
</body>
 
</html>


Output: 

 

Supported Browsers: The browsers supported by DOM FocusEvent relatedTarget Property are listed below: 

  • Google Chrome 26
  • Edge 12
  • Internet Explorer 9.0
  • Firefox 24.0
  • Apple Safari 7
  • Opera 15


Contact Us