HTML onfocus-evenement eigenschap

Voorbeeld

Voer JavaScript uit wanneer het invoerveld de nadruk krijgt:

<input type="text" id="fname"} onfocus="setStyle(this.id)">

Try it yourself

Browser support

IE Firefox Chrome Safari Opera

All mainstream browsers support the onfocus attribute.

Definition and usage

The onfocus attribute triggers when the element gains focus.

onfocus is commonly used with <input>, <select> and <a>.

Tip:The onfocus attribute is the opposite of the onblur attribute.

Note:The onfocus attribute is not applicable to the following elements: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> or <title>.

Differences between HTML 4.01 and HTML5

None.

Syntax

<element onfocus="script">

Attribute value

Value Description
script Script executed when onfocus occurs.