Prev Demo
JavaScript
>
How To Execute A Javascript Function On Focus Of The Element In Javascript?
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Onfocus</h1> Enter your name: <input type="text" name="txtName" id="txtName" onfocus="GotFocus(this.id)" /> <input type="button" id="btn" name="btn" value="Submit" /> <script> function GotFocus(id) { document.getElementById(id).style.background = "#c0c0c0"; } </script> <p><strong>Note: </strong>Click inside the text box to get the focus.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output