Example
Execute a JavaScript when an input field gets focus:
<input type="text" id="fname" onfocus="setStyle(this.id)">
Browser support
##IEFirefox ChromeSafariOpera##All major browsers support the onfocus attribute.
Definition and Usage
The onfocus attribute is triggered when an element receives focus.
onfocus is commonly used in ,
Tip: The onfocus attribute is the opposite of the onblur attribute.
Note: The onfocus attribute does not apply to the following elements:
, , ,