HTML | DOM FocusEvent relatedTarget Property

The DOM FocusEvent relatedTarget Property is used to returns a 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 focus.
  • For onblur and onfocusout events, the related element is the element that GOT focus.

Syntax:

event.relatedTarget

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



Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
Before focusing an element:

After focusing an element:

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

  • Google Chrome
  • Internet Explorer 9.0
  • Firefox 24.0
  • Apple Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.