Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onfocusin event

onfocusin event

Event Object Reference Event Object

Example

Execute JavaScript when the input field is about to get focus:

Try it »

More examples can be found at the bottom of this section.


Definition and Usage

The onfocusin event is triggered when an element is about to gain focus.

**Tip:** The onfocusin event is similar to onfocus the event. The main difference is that the onfocus event does not support bubbling. Therefore, if you want to know whether an element or its child elements get focus, you need to use the onfocusin event.

Tip: Although the Firefox browser does not support the onfocusin event, you can use the onfocus (using the optional parameter of the addEventListener() method) useCapturecapture listener event to check whether the element or its child elements get focus.

Tip: The opposite event of onfocusin is onfocusout events.


Browser support

Events
onfocusin Yes Yes Not supported Yes Yes

Note: In Chrome, Safari and Opera 15+ browsers, the onfocusin event using HTML DOM syntax may not work properly. However, as an HTML element, it works properly by using the addEventListener() method.


Syntax

In HTML:

<

element

onfocusin="

myScript

">

Try it

In JavaScript (Chrome, Safari and Opera 15+ may not work properly):

object

.onfocusin=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

object

.addEventListener("focusin",

myScript

);

Try it

Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.


Technical Details

Does it support bubbling: Yes
Is it cancelable: No
Event type: FocusEvent
Supported HTML tags: All HTML elements, except: , ,
, , ,