Execute a JavaScript when an input field gets focus:
More "Try it Yourself" examples below.
The onfocus attribute fires the moment that the element gets focus.
Onfocus is most often used with <input>, <select>, and <a>.
Tip: The onfocus attribute is the opposite of the onblur attribute.
Event Attribute | |||||
---|---|---|---|---|---|
onfocus | Yes | Yes | Yes | Yes | Yes |
None.
Value | Description |
---|---|
script | The script to be run on onfocus |
Supported HTML tags: | All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|
Using "onblur" together with the "onfocus" attribute:
HTML DOM reference: onfocus event