Javascript DOM HTML Textarea handle focus event
<!DOCTYPE html> <html> <body> <textarea rows="4" cols="50">Click me to assure that I get focus. Then, click the input field to make sure that it gets focus.</textarea><br><br> Input field: <input type="text" onfocus="getRelatedElement(event)"> <p id="demo"></p> <script> function getRelatedElement(event) { document.getElementById("demo").innerHTML = "The related element that lost focus was: " + event.relatedTarget.tagName; } </script>// ww w . j ava2 s.c o m </body> </html>