Javascript examples for DOM:Focus Event
The relatedTarget property returns the element related to the focus event.
For onfocus and onfocusin events, the related element is the element that loses focus.
For onblur and onfocusout events, the related element is the element that gets focus.
This property is read-only.
A reference to the related element, or null if there is no related element
The following code shows how to get the related element an onfocus event.
<!DOCTYPE html> <html> <body> <textarea rows="4" cols="50">Click me. Then, click the input field.</textarea><br><br> Input field: <input type="text" onfocus="getRelatedElement(event)"> <script> function getRelatedElement(event) { console.log("The related element that lost focus was: " + event.relatedTarget.tagName); } </script>/*from ww w. ja v a 2 s. co m*/ </body> </html>